Using optfun command to solve lagrange multipliers

1 vue (au cours des 30 derniers jours)
Tyler Luzar
Tyler Luzar le 15 Oct 2019
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.

Réponses (1)

Koushik Kureti
Koushik Kureti le 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

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by