Using optfun command to solve lagrange multipliers

조회 수: 2 (최근 30일)
Tyler Luzar
Tyler Luzar 2019년 10월 15일
답변: Koushik Kureti 2020년 3월 12일
hello,
I was given this code to run an optfun command, and I am a little confused how the optfun function works.
function F = optfun(pair)
x = pair(1);
y = pair(2);
F = [3*y+.001*y*exp(x)-4*x, x^2+y^2-25];
end
Any help would be great! I need to solve a lagrange multiplier with this.

답변 (1개)

Koushik Kureti
Koushik Kureti 2020년 3월 12일
Hello,
‘optfun’ is function name taking input arguments ‘pair’. Return value of the function is stored in F.
X is assigned with first value of pair. Y is assigned with second value of pair.
Now F has two values, where first value is 3*y+.001*y*exp(x)-4*x and second value are x^2+y^2-25.
At the end F is returned. You can call the function by ‘optfun’ (pair) where defining the pair before calling.
Example:
pair = [1 2];
disp(optfun(pair));
function F = optfun(pair)
x = pair(1);
y = pair(2);
F = [3*y+.001*y*exp(x)-4*x, x^2+y^2-25];
end
Output:
2.0054 -20.0000

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by