Finding all existing minimums of a function

I have this function:
I need to find all existing minimums of this function using fminsearch and also draw a 3D plot with minimum points highlighted on it.
What I've tried so far:
fun2 = @(x,y)x^4+y^4-2*x^2+4*x*y-2*y^2+1
x = fminsearch(@(v) fun2(v(1),v(2)),[-5,-5])
figure
[X, Y] = meshgrid(-2:0.1:2);
surf(X,Y,fun2(X,Y));
Result doesn't seem right:

 採用された回答

Image Analyst
Image Analyst 2021 年 4 月 25 日

0 投票

If you're going to pass in matrices for x and y, like X and Y from the output of meshgrid, you're going to have to use dots in the operators in your function:
fun2 = @(x,y) x .^ 4 + y .^ 4 - 2 * x .^ 2 + 4 * x .* y - 2 * y .^2 + 1;

3 件のコメント

Saba Asanidze
Saba Asanidze 2021 年 4 月 25 日
Thank you, now plot looks good but how do I get all the minimums of my function? Right now fminsearch gives me only one point (-1.4142,1.4142) but according to Wolfram point (1.4142,-1.4142) is also a minimum.
Image Analyst
Image Analyst 2021 年 4 月 25 日
I don't know. If it were me, I'd do it numerically. I'd evaluate the function everywhere, like between -2 and 2 or -5 and 5 or whatever you want, and then use imregionalmin() in the Image Processing Toolbox to find the local min locations.
Walter Roberson
Walter Roberson 2021 年 4 月 25 日
fminsearch only ever returns one location per call. If you call it with different initial values it may return a different location.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by