Hi,
Curve fitting is the problem 11 in Model Building by H. Paul Williams
https://www.amazon.fr/Model-Building-Mathematical-Programming-Williams/dp/1118443330?cm_mc_uid=56329990040415039023459&cm_mc_sid_50200000=1507305800&cm_mc_sid_52640000=
The goal is to find the best straight line or the best quadratic curve for n given points.
With OPL this is quite easy:
.dat
n=19;
x = [0.0, 0.5, 1.0, 1.5, 1.9, 2.5, 3.0, 3.5, 4.0, 4.5,
5.0, 5.5, 6.0, 6.6, 7.0, 7.6, 8.5, 9.0, 10.0];
y = [1.0, 0.9, 0.7, 1.5, 2.0, 2.4, 3.2, 2.0, 2.7, 3.5,
1.0, 4.0, 3.6, 2.7, 5.7, 4.6, 6.0, 6.8, 7.3];
And then for the straight line:
.mod
int n=...;
range points=1..n;
float x[points]=...;
float y[points]=...;
// y== b*x+a
dvar float a;
dvar float b;
minimize sum(i in points) abs(b*x[i]+a-y[i]);
//minimize max(i in points) abs(b*x[i]+a-y[i]);
subject to
{
}
execute
{
writeln("b=",b);
writeln("a=",a);
}
and for the quadratic curve
.mod
int n=...;
range points=1..n;
float x[points]=...;
float y[points]=...;
// y== c*x*x+b*x+a
dvar float a;
dvar float b;
dvar float c;
minimize sum(i in points) abs(c*x[i]*x[i]+b*x[i]+a-y[i]);
//minimize max(i in points) abs(c*x[i]*x[i]+b*x[i]+a-y[i]);
subject to
{
}
execute
{
writeln("c=",c);
writeln("b=",b);
writeln("a=",a);
}
regards
Many other examples in https://www.linkedin.com/pulse/model-building-oplcplex-alex-fleischer/
#DecisionOptimization#OPLusingCPLEXOptimizer