lemon-project-template-glpk

annotate deps/glpk/examples/qfit.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 /*Quadratic Curve Fitting Solution
alpar@9 2
alpar@9 3 Find a plausable quadratic fit to a sample of points
alpar@9 4
alpar@9 5 Nigel_Galloway@operamail.com
alpar@9 6 February 1st., 2009
alpar@9 7 */
alpar@9 8 set Sample;
alpar@9 9 param Sx {z in Sample};
alpar@9 10 param Sy {z in Sample};
alpar@9 11
alpar@9 12 var a;
alpar@9 13 var b;
alpar@9 14 var c;
alpar@9 15
alpar@9 16 equalz1 :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];
alpar@9 17 equalz2 :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];
alpar@9 18 equalz3 :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];
alpar@9 19
alpar@9 20 solve;
alpar@9 21
alpar@9 22 printf "\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);
alpar@9 23
alpar@9 24 data;
alpar@9 25
alpar@9 26 param:
alpar@9 27 Sample: Sx Sy :=
alpar@9 28 1 0 1
alpar@9 29 2 0.5 0.9
alpar@9 30 3 1 0.7
alpar@9 31 4 1.5 1.5
alpar@9 32 5 1.9 2
alpar@9 33 6 2.5 2.4
alpar@9 34 7 3 3.2
alpar@9 35 8 3.5 2
alpar@9 36 9 4 2.7
alpar@9 37 10 4.5 3.5
alpar@9 38 11 5 1
alpar@9 39 12 5.5 4
alpar@9 40 13 6 3.6
alpar@9 41 14 6.6 2.7
alpar@9 42 15 7 5.7
alpar@9 43 16 7.6 4.6
alpar@9 44 17 8.5 6
alpar@9 45 18 9 6.8
alpar@9 46 19 10 7.3
alpar@9 47 ;
alpar@9 48
alpar@9 49 end;