Using optfun command to solve lagrange multipliers

1 visualización (últimos 30 días)
Tyler Luzar
Tyler Luzar el 15 de Oct. de 2019
Respondida: Koushik Kureti el 12 de Mzo. de 2020
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.

Respuestas (1)

Koushik Kureti
Koushik Kureti el 12 de Mzo. de 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

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by