How to find minimum y value numerically using the fminsearch function?

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.

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 6 月 1 日
編集済み: Walter Roberson 2016 年 6 月 1 日

0 投票

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 件のコメント

Bella
Bella 2016 年 6 月 1 日
could you explain what is happening in this code? It is not the same as the format of the x value.
Walter Roberson
Walter Roberson 2016 年 6 月 1 日
I had a typing mistake in defining fvec; it is corrected now.
Due to round-off error and finite precision, you might end up with a value close to the theoretical location [10/3, -2/3] that come out with the same minimum value
Bella
Bella 2016 年 6 月 1 日
okay, those are the values that I got. So would -2/3 be the minimum y value then? Because it is the lowest of the two?
Walter Roberson
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.

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2016 年 5 月 31 日

コメント済み:

2016 年 6 月 1 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by