How to find maximum of a multivariable function using max()

How to find maximum of a multivariable function using max(). Let's denote z = (y+cos(y))/(x^2) for x,y belonging to [1,15].

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 29 日
編集済み: Ameer Hamza 2020 年 3 月 30 日

0 投票

You can use fmincon function to find maximum value
z = @(x,y) (y+cos(y))./(x.^2);
sol = fmincon(@(x) -z(x(1),x(2)), 10*rand(2,1), [], [], [], [], [1;1], [15;15]);
x_sol = sol(1);
y_sol = sol(2);

4 件のコメント

madhan ravi
madhan ravi 2020 年 3 月 29 日
I think you mean't
y_sol = sol(2)
Ameer Hamza
Ameer Hamza 2020 年 3 月 30 日
madhan, Thanks for pointing out.
enter
enter 2020 年 3 月 30 日
If I use fmincon a few times it tends to give bad results
Ameer Hamza
Ameer Hamza 2020 年 3 月 30 日
Michal, this is the limitation of the numerical optimization algorithm. They are sensitive to the initial guess. I found that for your objective function, 'interior-point' algorithm gives consistent results.
z = @(x,y) (y+cos(y))./(x.^2);
opts = optimoptions('fmincon', 'Algorithm', 'interior-point');
sol = fmincon(@(x) -z(x(1),x(2)), rand(1,2), [], [], [], [], [1;1], [15;15], [], opts);
x_sol = sol(1);
y_sol = sol(2);

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2020 年 3 月 29 日

コメント済み:

2020 年 3 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by