Help with a minimize problem
1 view (last 30 days)
Show older comments
Edited: Walter Roberson on 6 Mar 2017
unction b = two_var(v)
x = v(1);
y = v(2);
b = 242*log(1-x-y)+120*log(2*x-x^2-2*x*y)+79*log(2*y-y^2-2*x*y)+33*log(2*x*y);
v = [0.5,0.5]
a = fminsearch(@two_var,v);
I'm trying to minimize this function with the next code. The answer is x=0.247 and y=0.173
I leave the link where the problem comes from. Page 4
John D'Errico on 5 Mar 2017
Edited: John D'Errico on 5 Mar 2017
Time to think about your function. ALWAYS do that. Plot it if possible.
fun = @(x,y) 242*log(1-x-y)+120*log(2*x-x^2-2*x*y)+79*log(2*y-y^2-2*x*y)+33*log(2*x*y);
609.016175390547 + 625.176938064369i
So some values of x and y generate -inf. Some generate complex numbers. That is completely expected, since the log function does nasty stuff at 0 or negative values. Well, nasty in terms of what fminsearch will expect.
Basic rule: fminsearch expects a continuous, real valued function of the inputs.
If that presumption fails, then expect all hell to break loose in the eyes of fminsearch.
So, what do we see? First, the function is certainly unbounded from below, going to -inf along the line
x + y = 1
Next, it appears to have a MAXIMUM at the location you describe.
So honestly, I think you are confused. Are you trying to MAXIMIZE this function?
fminseach is a MINIMIZATION tool. You can make it maximize by negating the function as returned. It still minimizes, but the negative of your original function, so a maximum.
fun2 = @(xy) -fun(xy(1),xy(2));
[xymax,fmax] = fminsearch(fun2,[.2 .2])
More Answers (2)
kowshik Thopalli on 5 Mar 2017
I dont understand.
two_var =@(x) 242*log(1-x(1)-x(2))+120*log(2*x(1)-x(1)^2-2*x(1)*x(2))+79*log(2*x(2)-x(2)^2-2*x(1)*x(2))+33*log(2*x(1)*x(2));
v = [0.5,0.5];
x = fminsearch(fun,v)
this gives me x =
You forgot to attach the link. Changing v would give a different answer. What is it that you exactly want to do?
Roger Stafford on 5 Mar 2017
It is quite possible for functions such as yours to have more than one point of local minimum. If that is the case, the one that fminsearch will arrive at will depend on the given initial estimate. You need to try a different initial estimate if you are to arrive at the value you refer to in the MIT article.
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!