How to find minimum y value numerically using the fminsearch function?
6 次查看(过去 30 天)
显示 更早的评论
For the equation f(x,y)=-8x+x^2+12y+4y^2-2xy... I found the minimum x value by putting the anonymous function using x1 for x and x2 for y then the fminsearch code and got -17.3333. But now I am not sure how to find the minimum y value.
0 个评论
回答(1 个)
Walter Roberson
2016-6-1
编辑:Walter Roberson
2016-6-1
f = @(x,y) -8*x+x.^2+12*y+4*y.^2-2.*x.*y;
fvec = @(X) f(X(1), X(2));
[bestxy, fval] = fminsearch(fvec, rand(1,2));
bestx = bestxy(1); besty = bestxy(2);
Caution: the solution is not unique! The equation describes an ellipse (or something similar to one.)
4 个评论
Walter Roberson
2016-6-1
bestx is the x value at the minima. besty is the y value at the minima. Not because it is the lower of the two, but forced because of the order we programmed.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!