COIN-OR::LEMON - Graph Library

source: lemon-project-template-glpk/deps/glpk/examples/yacfs.mod @ 9:33de93886c88

subpack-glpk
Last change on this file since 9:33de93886c88 was 9:33de93886c88, checked in by Alpar Juttner <alpar@…>, 13 years ago

Import GLPK 4.47

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