COIN-OR::LEMON - Graph Library

source: lemon-project-template-glpk/deps/glpk/examples/xyacfs.mod

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

Import GLPK 4.47

File size: 1.5 KB
RevLine 
[9]1/*Extended Yet Another Curve Fitting Solution (The poor man's RMA)
2
3  An extension of yacfs.mod adding a Weight parameter:
4    When set to 1 the model produces best fit by least squares with all error in y and none in x (YonX);
5    When set to zero the model produces best fit by least squares with all error in x and none in y (XonY);
6    When set to 0.5 the model assumes equal error in x and y producing results similar to fitting by Reduced Major Axis Analysis.
7
8  Nigel_Galloway@operamail.com
9  November 5th., 2009
10*/
11set Sample;
12param Sx {z in Sample};
13param Sy {z in Sample};
14param Weight := 0.5;
15
16var a;
17var b;
18var p;
19var q;
20
21XonY1 :sum{z in Sample} q*Sy[z]*Sy[z] + sum{z in Sample} p*Sy[z] = sum{z in Sample} Sy[z]*Sx[z];
22XonY2 :sum{z in Sample} q*Sy[z] + sum{z in Sample} p = sum{z in Sample} Sx[z];
23YonX1 :sum{z in Sample} a*Sx[z]*Sx[z] + sum{z in Sample} b*Sx[z] = sum{z in Sample} Sy[z]*Sx[z];
24YonX2 :sum{z in Sample} a*Sx[z] + sum{z in Sample} b = sum{z in Sample} Sy[z];
25
26solve;
27
28param W := Weight*a + (1-Weight)*(1/q);
29printf "\nbest linear fit is:\n\ty = %f %s %fx\n\n", b*Weight - (1-Weight)*(p/q), if W < 0 then "-" else "+", abs(W);
30
31data;
32
33param:
34Sample:   Sx    Sy :=
35  1         0    1
36  2       0.5  0.9
37  3         1  0.7
38  4       1.5  1.5
39  5       1.9    2
40  6       2.5  2.4
41  7         3  3.2
42  8       3.5    2
43  9         4  2.7
44 10       4.5  3.5
45 11         5    1
46 12       5.5    4
47 13         6  3.6
48 14       6.6  2.7
49 15         7  5.7
50 16       7.6  4.6
51 17       8.5    6
52 18         9  6.8
53 19        10  7.3
54;
55
56end;
Note: See TracBrowser for help on using the repository browser.