how to find the minimum value based on two independent value
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
suby
am 17 Mär. 2015
Kommentiert: suby
am 24 Mär. 2015
Hi, guys, i have a problem and dont know how to solve. i have two independent variale:x1, x2, y is dependent output value.i want to find when y will be the minimum value. I heard about surface response method is useful to solve this problem, but it is a little complicated. could you give me an advice to solve problem using matlab, thank you! here list the results
x1 x2 y
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
6 Kommentare
Andrew Newell
am 18 Mär. 2015
Bearbeitet: Andrew Newell
am 18 Mär. 2015
I think you're having trouble articulating what you really want. You talk about finding the minimum in a table, which is pretty trivial in this case because you can just eyeball the third column. The smallest value is 0.009, for which x1 = 0.25 and x2 = 1.5. However, you're talking about changing inputs and the minimum being "close to" x1=0.2 and x2=1.5. That implies there is a function that generates y. That is quite a different problem, involving optimization.
Akzeptierte Antwort
John D'Errico
am 21 Mär. 2015
Bearbeitet: John D'Errico
am 21 Mär. 2015
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])
Weitere Antworten (2)
Andrew Newell
am 18 Mär. 2015
I'm going to assume you're really trying to minimize a function of two variables and show how you can explore it to get some insight. First, I'll read your table in as a matrix:
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];
Now, a contour plot is a good idea, but that requires rearranging the points:
x1 = 0.15:.05:.3;
x2 = 1:.5:2.5;
[x1,x2] = meshgrid(x1,x2);
y = reshape(M(:,3),size(x1));
You'll find that [x1(:) x2(:) y(:)] gives you back your table. Now we'll plot the data:
contourf(x1,x2,y);
xlabel('x1')
ylabel('x2')
colorbar
This appears to be a fairly smooth function with a minimum somewhere near where you have guessed it is. You should be able to find an accurate minimum using fminsearch, but I can't tell you the details because you haven't told me what your function is.
1 Kommentar
Alan Weiss
am 18 Mär. 2015
As with the other comments you have gotten, I am going to assume that there is a function, say myfun(x1, x2), that gives you your y variables. You are looking for the minimum of y, and want to know how to find the x1 and x2 that give the minimum.
This is a job for fminsearch. The only issue is getting your function of two variables to be a function of one vector variable x = [x1,x2]. Do it like this.
fun = @(x)myfun(x(1),x(2)); % x is a 2-component vector
solution = fminsearch(fun,[0.2,1.5]) % Put in a good start guess
Alan Weiss
MATLAB mathematical toolbox documentation
2 Kommentare
Image Analyst
am 21 Mär. 2015
Explain why you want an interpolated value that does not exist in your table. What are you going to do with that information? Why is the value in the table not sufficient for what you want to do? In other words, describe your "use case".
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!