You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
933 B

2 months ago
  1. /*Yet Another Curve Fitting Solution
  2. Obviously this solution produces the same answer
  3. as examples/cflsq.mod
  4. Nigel_Galloway@operamail.com
  5. February 1st., 2009
  6. */
  7. set Sample;
  8. param Sx {z in Sample};
  9. param Sy {z in Sample};
  10. var a;
  11. var b;
  12. 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];
  13. equalz2 :sum{z in Sample} a*Sx[z] + sum{z in Sample} b = sum{z in Sample} Sy[z];
  14. solve;
  15. printf "\nbest linear fit is:\n\ty = %f %s %fx\n\n", b, if a < 0 then "-" else "+", abs(a);
  16. data;
  17. param:
  18. Sample: Sx Sy :=
  19. 1 0 1
  20. 2 0.5 0.9
  21. 3 1 0.7
  22. 4 1.5 1.5
  23. 5 1.9 2
  24. 6 2.5 2.4
  25. 7 3 3.2
  26. 8 3.5 2
  27. 9 4 2.7
  28. 10 4.5 3.5
  29. 11 5 1
  30. 12 5.5 4
  31. 13 6 3.6
  32. 14 6.6 2.7
  33. 15 7 5.7
  34. 16 7.6 4.6
  35. 17 8.5 6
  36. 18 9 6.8
  37. 19 10 7.3
  38. ;
  39. end;