How to find maximum of a function of 2 variables

7 ビュー (過去 30 日間)
enter
enter 2020 年 3 月 29 日
コメント済み: Alex Sha 2020 年 4 月 17 日
I have a function z = cos(x^2 + y^2) and the assumption that both x and y belong to interval 1;5. How can I find the maximum value of the function z? I thought about using fminsearch for finding minimum of -z, but I’m new to Matlab and it doesn’t work.
  1 件のコメント
Alex Sha
Alex Sha 2020 年 4 月 17 日
Obviously, the maximum value of cos() should be 1, in the range of [1,5], there are multi-solutions:
1:
x: 2.32564131982953
y: 4.44118606739161
2:
x: 4.43419681301284
y: 2.33893989844493

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

採用された回答

Star Strider
Star Strider 2020 年 3 月 29 日
One approach:
z = @(x,y) cos(x.^2 + y.^2);
XY = fminsearch(@(b)norm(-z(b(1),b(2))), [3; 3])
producing:
XY =
2.96385862016178
2.91449853520917
  10 件のコメント
enter
enter 2020 年 3 月 29 日
That's quite a sophisticated solution. is there a method like fminbnd, but for multivariable functions?
Star Strider
Star Strider 2020 年 3 月 29 日
I referred to it earlier: fmincon. The would be more appropriate, since it is for multivariable functions, and it allows constraints on them.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOptimization Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by