lemon-project-template-glpk
diff deps/glpk/examples/cflsq.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/cflsq.mod Sun Nov 06 20:59:10 2011 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +/*Curve fitting problem by Least Squares 1.5 + Nigel_Galloway@operamail.com 1.6 + October 1st., 2007 1.7 +*/ 1.8 +set Sample; 1.9 +param Sx {z in Sample}; 1.10 +param Sy {z in Sample}; 1.11 + 1.12 +var X; 1.13 +var Y; 1.14 +var Ex{z in Sample}; 1.15 +var Ey{z in Sample}; 1.16 + 1.17 +/* sum of variances is zero for Sx*/ 1.18 +variencesX{z in Sample}: X + Ex[z] = Sx[z]; 1.19 +zumVariancesX: sum{z in Sample} Ex[z] = 0; 1.20 +/* sum of variances is zero for Sy*/ 1.21 +variencesY{z in Sample}: Y + Ey[z] = Sy[z]; 1.22 +zumVariancesY: sum{z in Sample} Ey[z] = 0; 1.23 + 1.24 +solve; 1.25 + 1.26 +param b1 := (sum{z in Sample} Ex[z]*Ey[z])/(sum{z in Sample} Ex[z]*Ex[z]); 1.27 +printf "\nbest linear fit is:\n\ty = %f %s %fx\n\n", Y-b1*X, if b1 < 0 then "-" else "+", abs(b1); 1.28 + 1.29 +data; 1.30 + 1.31 +param: 1.32 +Sample: Sx Sy := 1.33 + 1 0 1 1.34 + 2 0.5 0.9 1.35 + 3 1 0.7 1.36 + 4 1.5 1.5 1.37 + 5 1.9 2 1.38 + 6 2.5 2.4 1.39 + 7 3 3.2 1.40 + 8 3.5 2 1.41 + 9 4 2.7 1.42 + 10 4.5 3.5 1.43 + 11 5 1 1.44 + 12 5.5 4 1.45 + 13 6 3.6 1.46 + 14 6.6 2.7 1.47 + 15 7 5.7 1.48 + 16 7.6 4.6 1.49 + 17 8.5 6 1.50 + 18 9 6.8 1.51 + 19 10 7.3 1.52 +; 1.53 + 1.54 +end;