lemon-project-template-glpk
view deps/glpk/examples/qfit.mod @ 9:33de93886c88
Import GLPK 4.47
author | Alpar Juttner <alpar@cs.elte.hu> |
---|---|
date | Sun, 06 Nov 2011 20:59:10 +0100 |
parents | |
children |
line source
1 /*Quadratic Curve Fitting Solution
3 Find a plausable quadratic fit to a sample of points
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};
12 var a;
13 var b;
14 var c;
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];
20 solve;
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);
24 data;
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 ;
49 end;