COIN-OR::LEMON - Graph Library

source: glpk-cmake/examples/qfit.mod @ 1:c445c931472f

Last change on this file since 1:c445c931472f was 1:c445c931472f, checked in by Alpar Juttner <alpar@…>, 10 years ago

Import glpk-4.45

  • Generated files and doc/notes are removed
File size: 1.2 KB
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*/
8set Sample;
9param Sx {z in Sample};
10param Sy {z in Sample};
11
12var a;
13var b;
14var c;
15
16equalz1 :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];
17equalz2 :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];
18equalz3 :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
20solve;
21
22printf "\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
24data;
25
26param:
27Sample:   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
49end;
Note: See TracBrowser for help on using the repository browser.