author | Alpar Juttner <alpar@cs.elte.hu> |
Sun, 05 Dec 2010 17:35:23 +0100 | |
changeset 2 | 4c8956a7bdf4 |
permissions | -rw-r--r-- |
1 /*Yet Another Curve Fitting Solution
3 Obviously this solution produces the same answer
4 as examples/cflsq.mod
6 Nigel_Galloway@operamail.com
7 February 1st., 2009
8 */
9 set Sample;
10 param Sx {z in Sample};
11 param Sy {z in Sample};
13 var a;
14 var b;
16 equalz1 :sum{z in Sample} a*Sx[z]*Sx[z] + sum{z in Sample} b*Sx[z] = sum{z in Sample} Sy[z]*Sx[z];
17 equalz2 :sum{z in Sample} a*Sx[z] + sum{z in Sample} b = sum{z in Sample} Sy[z];
19 solve;
21 printf "\nbest linear fit is:\n\ty = %f %s %fx\n\n", b, if a < 0 then "-" else "+", abs(a);
23 data;
25 param:
26 Sample: Sx Sy :=
27 1 0 1
28 2 0.5 0.9
29 3 1 0.7
30 4 1.5 1.5
31 5 1.9 2
32 6 2.5 2.4
33 7 3 3.2
34 8 3.5 2
35 9 4 2.7
36 10 4.5 3.5
37 11 5 1
38 12 5.5 4
39 13 6 3.6
40 14 6.6 2.7
41 15 7 5.7
42 16 7.6 4.6
43 17 8.5 6
44 18 9 6.8
45 19 10 7.3
46 ;
48 end;