author | Alpar Juttner <alpar@cs.elte.hu> |
Mon, 06 Dec 2010 13:09:21 +0100 | |
changeset 1 | c445c931472f |
permissions | -rw-r--r-- |
1 /*
3 Curve fitting problem 12.11(b) H P Williams "Model Building in Mathematical Programming"
5 Dr. H J Mackenzie
6 HARD software
7 hjm@hardsoftware.com
9 2006-01-23
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 var z;
41 # define objective function
43 minimize deviation: z;
45 # define equation constraint
47 s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i];
49 # define deviation constrains
51 s.t. u_deviation {i in I} : z - u[i] >= 0;
52 s.t. v_deviation {i in I} : z - v[i] >= 0;
54 solve;
56 printf "y = %.4fx + %.4f Max deviation = %.4f\n", b, a, z;
58 /*
59 *
60 * DATA section
61 *
62 */
64 data;
66 param : I : x y :=
67 1 0 1
68 2 0.5 0.9
69 3 1 0.7
70 4 1.5 1.5
71 5 1.9 2
72 6 2.5 2.4
73 7 3 3.2
74 8 3.5 2
75 9 4 2.7
76 10 4.5 3.5
77 11 5 1
78 12 5.5 4
79 13 6 3.6
80 14 6.6 2.7
81 15 7 5.7
82 16 7.6 4.6
83 17 8.5 6
84 18 9 6.8
85 19 10 7.3
86 ;
88 end;