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일
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

I think you mean't
y_sol = sol(2)
madhan, Thanks for pointing out.
If I use fmincon a few times it tends to give bad results
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 Exchange에서 Nonlinear 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