Ok. So since you now tell us that you have ONLY a table of data, with no function.
Then you need to recognize that without some way to predict a value between the tabular points, there is no way to find a minimum value. You need some scheme to interpolate, or some approximate function that fits the data. The simple approach is to interpolate, here using interp2 as the logical choice.
The problems with interp2 in this approach are:
1. You will need to use the 'spline' method, as a lower order scheme will be a bit boring.
2. Interp2 does not extrapolate well, and extrapolation of a spline is just silly. So you will want to use a bounded solver.
We can see how this works on your data.
M = [0.15 1.0 0.863;
0.15 1.5 0.050;
0.15 2.0 1.267;
0.15 2.5 3.082;
0.20 1.0 0.635;
0.20 1.5 0.010;
0.20 2.0 0.690;
0.20 2.5 1.900;
0.25 1.0 0.629;
0.25 1.5 0.009;
0.25 2.0 0.617;
0.25 2.5 1.522;
0.30 1.0 0.701;
0.30 1.5 0.016;
0.30 2.0 0.593;
0.30 2.5 1.452];
Simple observation shows a minimum near (x,y) = (0.25,1.5), but we can find that programmatically easily enough using the min function.
x = M(:,1);
y = M(:,2);
z = M(:,3);
[minz,ind] = min(z)
minz =
0.009
ind =
10
M(10,:)
ans =
0.25 1.5 0.009
Now lets define a function that can be sued to interpolate this tabular set of data.
xi = unique(x);
yi = unique(y);
fun = @(xy) interp2(xi,yi,reshape(z,4,4),xy(1),xy(2),'spline');
So for example...
fun([.25 ,1.5])
ans =
0.009
fun([.2,1.75])
ans =
0.23531
It is always a good idea to plot EVERYTHING.
contour(xi,yi,reshape(z,4,4),[.1 .2 .3 .4 .5 .75 1 2 3])
Now lets use a solver on fun.
lb = [.15 ,1];
ub = [.3, 2.5];
[xymin,zmin] = fminsearchbnd(fun,[.25,1.5],lb,ub)
xymin =
0.22732 1.4453
zmin =
-0.001039
See that I used my own fminsearchbnd, found on the file exchange. It allows me to add bounds to the search, so I need not worry about the solver going outside of the bounds.
I could also have used a model of this data. A polynomial model should be sufficient, and nothing of too high an order, as the function is a simple one.
p = polyfitn([x,y],z,3)
p =
ModelTerms: [10x2 double]
Coefficients: [-375.33 58.84 200.68 -7.124 -8.072 -43.525 -1.3727 10.692 -18.922 14.639]
ParameterVar: [87301 314.28 40837 3.1428 102.77 2120.7 0.087301 2.5751 9.3821 14.673]
ParameterStd: [295.47 17.728 202.08 1.7728 10.138 46.052 0.29547 1.6047 3.063 3.8305]
DoF: 6
p: [0.25101 0.016023 0.35902 0.0069707 0.45623 0.38108 0.0035193 0.00055274 0.00082733 0.0087443]
R2: 0.99415
AdjustedR2: 0.98537
RMSE: 0.060688
VarNames: {'X1' 'X2'}
psym = vpa(polyn2sym(p),16)
psym =
- 375.3333333333113*X1^3 + 58.83999999999785*X1^2*X2 + 200.6799999999904*X1^2 - 7.123999999999711*X1*X2^2 - 8.072*X1*X2 - 43.52466666666535*X1 - 1.372666666666667*X2^3 + 10.6924*X2^2 - 18.92153333333317*X2 + 14.63875
pgrad = gradient(psym);
groots = solve(pgrad);
groots.X1
ans =
0.29927874279651926226688855470807
0.20749483993099085441217447597139
0.32278193339635663611070377153234 - 0.040069824732610684465833401918639i
0.32278193339635663611070377153234 + 0.040069824732610684465833401918639i
groots.X2
ans =
1.431025448839533109541965980622
1.4500035963111515399851171239296
2.660439130764919498188972022711 + 0.062485973176614710041936383492915i
2.660439130764919498188972022711 - 0.062485973176614710041936383492915i
Which of those roots is the minimum?
syms X1 X2
subs(psym,{X1,X2},{groots.X1,groots.X2})
ans =
0.041173813812552132138095037065494
-0.10874928276576993381362733327689
1.4706001978222628873166798300997 + 0.061660508055862572262913258951546i
1.4706001978222628873166798300997 - 0.061660508055862572262913258951546i
So the model solution lives at:
[groots.X1(2),groots.X2(2)]
ans =
[ 0.20749483993099085441217447597139, 1.4500035963111515399851171239296]
Don't forget to plot the modeled surface...
ezsurf(psym,[.15,.3],[1,2.5])
Best Answer