フィルターのクリア

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 Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by