lemon-project-template-glpk

diff deps/glpk/examples/xyacfs.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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/deps/glpk/examples/xyacfs.mod	Sun Nov 06 20:59:10 2011 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +/*Extended Yet Another Curve Fitting Solution (The poor man's RMA)
     1.5 +
     1.6 +  An extension of yacfs.mod adding a Weight parameter:
     1.7 +    When set to 1 the model produces best fit by least squares with all error in y and none in x (YonX);
     1.8 +    When set to zero the model produces best fit by least squares with all error in x and none in y (XonY);
     1.9 +    When set to 0.5 the model assumes equal error in x and y producing results similar to fitting by Reduced Major Axis Analysis.
    1.10 +
    1.11 +  Nigel_Galloway@operamail.com
    1.12 +  November 5th., 2009
    1.13 +*/
    1.14 +set Sample;
    1.15 +param Sx {z in Sample};
    1.16 +param Sy {z in Sample};
    1.17 +param Weight := 0.5;
    1.18 +
    1.19 +var a;
    1.20 +var b;
    1.21 +var p;
    1.22 +var q;
    1.23 +
    1.24 +XonY1 :sum{z in Sample} q*Sy[z]*Sy[z] + sum{z in Sample} p*Sy[z] = sum{z in Sample} Sy[z]*Sx[z];
    1.25 +XonY2 :sum{z in Sample} q*Sy[z] + sum{z in Sample} p = sum{z in Sample} Sx[z];
    1.26 +YonX1 :sum{z in Sample} a*Sx[z]*Sx[z] + sum{z in Sample} b*Sx[z] = sum{z in Sample} Sy[z]*Sx[z];
    1.27 +YonX2 :sum{z in Sample} a*Sx[z] + sum{z in Sample} b = sum{z in Sample} Sy[z];
    1.28 +
    1.29 +solve;
    1.30 +
    1.31 +param W := Weight*a + (1-Weight)*(1/q);
    1.32 +printf "\nbest linear fit is:\n\ty = %f %s %fx\n\n", b*Weight - (1-Weight)*(p/q), if W < 0 then "-" else "+", abs(W);
    1.33 +
    1.34 +data;
    1.35 +
    1.36 +param:
    1.37 +Sample:   Sx    Sy :=
    1.38 +  1         0    1
    1.39 +  2       0.5  0.9
    1.40 +  3         1  0.7
    1.41 +  4       1.5  1.5
    1.42 +  5       1.9    2
    1.43 +  6       2.5  2.4
    1.44 +  7         3  3.2
    1.45 +  8       3.5    2
    1.46 +  9         4  2.7
    1.47 + 10       4.5  3.5
    1.48 + 11         5    1
    1.49 + 12       5.5    4
    1.50 + 13         6  3.6
    1.51 + 14       6.6  2.7
    1.52 + 15         7  5.7
    1.53 + 16       7.6  4.6
    1.54 + 17       8.5    6
    1.55 + 18         9  6.8
    1.56 + 19        10  7.3
    1.57 +;
    1.58 +
    1.59 +end;