lemon-project-template-glpk

annotate 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
rev   line source
alpar@9 1 /*Extended Yet Another Curve Fitting Solution (The poor man's RMA)
alpar@9 2
alpar@9 3 An extension of yacfs.mod adding a Weight parameter:
alpar@9 4 When set to 1 the model produces best fit by least squares with all error in y and none in x (YonX);
alpar@9 5 When set to zero the model produces best fit by least squares with all error in x and none in y (XonY);
alpar@9 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.
alpar@9 7
alpar@9 8 Nigel_Galloway@operamail.com
alpar@9 9 November 5th., 2009
alpar@9 10 */
alpar@9 11 set Sample;
alpar@9 12 param Sx {z in Sample};
alpar@9 13 param Sy {z in Sample};
alpar@9 14 param Weight := 0.5;
alpar@9 15
alpar@9 16 var a;
alpar@9 17 var b;
alpar@9 18 var p;
alpar@9 19 var q;
alpar@9 20
alpar@9 21 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];
alpar@9 22 XonY2 :sum{z in Sample} q*Sy[z] + sum{z in Sample} p = sum{z in Sample} Sx[z];
alpar@9 23 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];
alpar@9 24 YonX2 :sum{z in Sample} a*Sx[z] + sum{z in Sample} b = sum{z in Sample} Sy[z];
alpar@9 25
alpar@9 26 solve;
alpar@9 27
alpar@9 28 param W := Weight*a + (1-Weight)*(1/q);
alpar@9 29 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);
alpar@9 30
alpar@9 31 data;
alpar@9 32
alpar@9 33 param:
alpar@9 34 Sample: Sx Sy :=
alpar@9 35 1 0 1
alpar@9 36 2 0.5 0.9
alpar@9 37 3 1 0.7
alpar@9 38 4 1.5 1.5
alpar@9 39 5 1.9 2
alpar@9 40 6 2.5 2.4
alpar@9 41 7 3 3.2
alpar@9 42 8 3.5 2
alpar@9 43 9 4 2.7
alpar@9 44 10 4.5 3.5
alpar@9 45 11 5 1
alpar@9 46 12 5.5 4
alpar@9 47 13 6 3.6
alpar@9 48 14 6.6 2.7
alpar@9 49 15 7 5.7
alpar@9 50 16 7.6 4.6
alpar@9 51 17 8.5 6
alpar@9 52 18 9 6.8
alpar@9 53 19 10 7.3
alpar@9 54 ;
alpar@9 55
alpar@9 56 end;