subpack-glpk
Line | |
---|
1 | /*Quadratic Curve Fitting Solution |
---|
2 | |
---|
3 | Find a plausable quadratic fit to a sample of points |
---|
4 | |
---|
5 | Nigel_Galloway@operamail.com |
---|
6 | February 1st., 2009 |
---|
7 | */ |
---|
8 | set Sample; |
---|
9 | param Sx {z in Sample}; |
---|
10 | param Sy {z in Sample}; |
---|
11 | |
---|
12 | var a; |
---|
13 | var b; |
---|
14 | var c; |
---|
15 | |
---|
16 | equalz1 :sum{z in Sample} a*Sx[z]*Sx[z]*Sx[z]*Sx[z] + sum{z in Sample} b*Sx[z]*Sx[z]*Sx[z] + sum{z in Sample} c*Sx[z]*Sx[z] = sum{z in Sample} Sy[z]*Sx[z]*Sx[z]; |
---|
17 | equalz2 :sum{z in Sample} a*Sx[z]*Sx[z]*Sx[z] + sum{z in Sample} b*Sx[z]*Sx[z] + sum{z in Sample} c*Sx[z] = sum{z in Sample} Sy[z]*Sx[z]; |
---|
18 | equalz3 :sum{z in Sample} a*Sx[z]*Sx[z] + sum{z in Sample} b*Sx[z] + sum{z in Sample} c = sum{z in Sample} Sy[z]; |
---|
19 | |
---|
20 | solve; |
---|
21 | |
---|
22 | printf "\nbest quadratic fit is:\n\ty = %f %s %fx %s %fx^2\n\n", c, if b < 0 then "-" else "+", abs(b), if a < 0 then "-" else "+", abs(a); |
---|
23 | |
---|
24 | data; |
---|
25 | |
---|
26 | param: |
---|
27 | Sample: Sx Sy := |
---|
28 | 1 0 1 |
---|
29 | 2 0.5 0.9 |
---|
30 | 3 1 0.7 |
---|
31 | 4 1.5 1.5 |
---|
32 | 5 1.9 2 |
---|
33 | 6 2.5 2.4 |
---|
34 | 7 3 3.2 |
---|
35 | 8 3.5 2 |
---|
36 | 9 4 2.7 |
---|
37 | 10 4.5 3.5 |
---|
38 | 11 5 1 |
---|
39 | 12 5.5 4 |
---|
40 | 13 6 3.6 |
---|
41 | 14 6.6 2.7 |
---|
42 | 15 7 5.7 |
---|
43 | 16 7.6 4.6 |
---|
44 | 17 8.5 6 |
---|
45 | 18 9 6.8 |
---|
46 | 19 10 7.3 |
---|
47 | ; |
---|
48 | |
---|
49 | end; |
---|
Note: See
TracBrowser
for help on using the repository browser.