Azzera filtri
Azzera filtri

Using optfun command to solve lagrange multipliers

6 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Koushik Kureti
Koushik Kureti il 12 Mar 2020
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

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by