필터 지우기
필터 지우기

How to find maximum of a function of 2 variables

조회 수: 55 (최근 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 CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by