author | Alpar Juttner <alpar@cs.elte.hu> |
Sun, 05 Dec 2010 17:35:23 +0100 | |
changeset 2 | 4c8956a7bdf4 |
permissions | -rw-r--r-- |
1 /*
3 Curve fitting problem 12.11(a) H P Williams "Model Building in Mathematical Programming"
5 Dr. H J Mackenzie
6 HARD software
7 hjm@hardsoftware.com
9 2006-01-05
11 */
13 # set of points
15 set I;
17 # independent variable
19 param x {i in I};
21 # dependent variable
23 param y {i in I};
25 # output input values
27 printf {i in I} "x = %.1f; y = %.1f\n", x[i], y[i];
29 # define equation variables
31 var a;
33 var b;
35 var u {i in I}, >= 0;
37 var v {i in I}, >= 0;
39 # define objective function
41 minimize error: sum {i in I} u[i] + sum {i in I} v[i];
43 # define equation constraint
45 s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i];
47 solve;
49 printf "y = %.4fx + %.4f\n", b, a;
51 /*
52 *
53 * DATA section
54 *
55 */
57 data;
59 param : I : x y :=
60 1 0 1
61 2 0.5 0.9
62 3 1 0.7
63 4 1.5 1.5
64 5 1.9 2
65 6 2.5 2.4
66 7 3 3.2
67 8 3.5 2
68 9 4 2.7
69 10 4.5 3.5
70 11 5 1
71 12 5.5 4
72 13 6 3.6
73 14 6.6 2.7
74 15 7 5.7
75 16 7.6 4.6
76 17 8.5 6
77 18 9 6.8
78 19 10 7.3
79 ;
81 end;