単調3次スプライン補間法(2)

 GLPK(Gnu Linear Programming Kit)の使い方がよく分からず,えらい手こずってしまった.2日ぐらいつぶしてしまった…….

 昨日の続きで,単調3次スプライン補間を実現する方法.

#mono.mod
param n, integer, >0;
param y{i in 1..n};
var alpha{i in 1..n-1};
var beta{i in 1..n-1};
var K,>= 0;

minimize COST: sum{i in 1..n-2} ( (-6+2*alpha[i]+4*beta[i])*(y[i+1]-y[i])+(-3+2*alpha[i+1]+beta[i+1])*(y[i+2]-y[i+1])+K );

s.t. CON2 {i in 1..n-2}: ( (-6+2*alpha[i]+4*beta[i])*(y[i+1]-y[i])+(-3+2*alpha[i+1]+beta[i+1])*(y[i+2]-y[i+1])+K ) >= 0;
s.t. CON3 {i in 1..n-2}: (beta[i]*(y[i+1]-y[i])-alpha[i+1]*(y[i+2]-y[i+1]))==0;
s.t. CON41{i in 1..n-1}: (-alpha[i]*(y[i+1]-y[i]))<=0;
s.t. CON42{i in 1..n-1}: (-beta[i]*(y[i+1]-y[i]))<=0;
s.t. CON43{i in 1..n-1}: ( (alpha[i]-beta[i]-3)*(y[i+1]-y[i]) )<=0;
s.t. CON44{i in 1..n-1}: ( (2*alpha[i]+beta[i]-9)*(y[i+1]-y[i]) )<=0;
s.t. CON45{i in 1..n-1}: ( (alpha[i]+2*beta[i]-9)*(y[i+1]-y[i]) )<=0;
s.t. CON46{i in 1..n-1}: ( (-alpha[i]+beta[i]-3)*(y[i+1]-y[i]) )<=0;

end;

#mono.dat
param n := 12;

param y :=
1 0
2 1
3 4.8
4 6
5 8
6 13
7 14
8 15.5
9 18
10 19
11 23
12 24.1;

end;

No. Column name St Activity
------ ------------ -- -------------
1 alpha[2] B 0.294892
2 alpha[1] B 2.25882
3 alpha[3] B 3
4 alpha[4] B 0
5 alpha[5] B 0.688235
6 alpha[6] B 3.79412
7 alpha[7] B 0.529412
8 alpha[8] B 0.706635
9 alpha[9] B 1.75342
10 alpha[10] B 0.34687
11 alpha[11] B 3.28133
12 beta[2] B 0.947368
13 beta[1] B 1.12059
14 beta[3] B 0
15 beta[4] B 1.72059
16 beta[5] B 0.758824
17 beta[6] B 0.794118
18 beta[7] B 1.17772
19 beta[8] B 0.701368
20 beta[9] B 1.38748
21 beta[10] B 0.902365
22 beta[11] B 0.281327
23 K B 2.55882

 実行コマンドは以下の通り.

glpsol -m mono.mod -d mono.dat -o mono.txt

これでそれっぽい答えが出てきます.なぜかMathematica(のMinimize)と結果が一致しない.図はまたいずれ,機会があれば…….