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.

81 lines
1.1 KiB

  1. /*
  2. Curve fitting problem 12.11(a) H P Williams "Model Building in Mathematical Programming"
  3. Dr. H J Mackenzie
  4. HARD software
  5. hjm@hardsoftware.com
  6. 2006-01-05
  7. */
  8. # set of points
  9. set I;
  10. # independent variable
  11. param x {i in I};
  12. # dependent variable
  13. param y {i in I};
  14. # output input values
  15. printf {i in I} "x = %.1f; y = %.1f\n", x[i], y[i];
  16. # define equation variables
  17. var a;
  18. var b;
  19. var u {i in I}, >= 0;
  20. var v {i in I}, >= 0;
  21. # define objective function
  22. minimize error: sum {i in I} u[i] + sum {i in I} v[i];
  23. # define equation constraint
  24. s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i];
  25. solve;
  26. printf "y = %.4fx + %.4f\n", b, a;
  27. /*
  28. *
  29. * DATA section
  30. *
  31. */
  32. data;
  33. param : I : x y :=
  34. 1 0 1
  35. 2 0.5 0.9
  36. 3 1 0.7
  37. 4 1.5 1.5
  38. 5 1.9 2
  39. 6 2.5 2.4
  40. 7 3 3.2
  41. 8 3.5 2
  42. 9 4 2.7
  43. 10 4.5 3.5
  44. 11 5 1
  45. 12 5.5 4
  46. 13 6 3.6
  47. 14 6.6 2.7
  48. 15 7 5.7
  49. 16 7.6 4.6
  50. 17 8.5 6
  51. 18 9 6.8
  52. 19 10 7.3
  53. ;
  54. end;