1 /*Curve fitting problem by Least Squares
2 Nigel_Galloway@operamail.com
6 param Sx {z in Sample};
7 param Sy {z in Sample};
14 /* sum of variances is zero for Sx*/
15 variencesX{z in Sample}: X + Ex[z] = Sx[z];
16 zumVariancesX: sum{z in Sample} Ex[z] = 0;
17 /* sum of variances is zero for Sy*/
18 variencesY{z in Sample}: Y + Ey[z] = Sy[z];
19 zumVariancesY: sum{z in Sample} Ey[z] = 0;
23 param b1 := (sum{z in Sample} Ex[z]*Ey[z])/(sum{z in Sample} Ex[z]*Ex[z]);
24 printf "\nbest linear fit is:\n\ty = %f %s %fx\n\n", Y-b1*X, if b1 < 0 then "-" else "+", abs(b1);