How can I solve a Lagrange equation?
21 views (last 30 days)
Show older comments
Dear all,
I need to solve a Lagrange equation. How can I get derivate of a function in MATLAB?
The equations are;
g=x_1+x_2+x_3 - 10
L=λ*g+V=12*x_1-x_1^2+8*x_2-x_2^2+18*x_3-3*x_3^2+λ*x_1+λ*x_2+λ*x_3-10*λ
what I want to do is find the derivates;
∂L/(∂x_1 )=0
∂L/(∂x_2 )=0
∂L/(∂x_3 )=0
∂L/(∂λ)=0
and finally find the values of x_1, x_2 , x_3 , λ , L and V.
0 Comments
Accepted Answer
Torsten
on 19 Oct 2022
Edited: Torsten
on 19 Oct 2022
syms x1 x2 x3 lambda
g = x1+x2+x3 - 10;
L = 12*x1-x1^2+8*x2-x2^2+18*x3-3*x3^2+lambda*g;
Lx1 = diff(L,x1);
Lx2 = diff(L,x2);
Lx3 = diff(L,x3);
Llambda = diff(L,lambda);
s = solve([Lx1==0,Lx2==0,Lx3==0,Llambda==0],[x1 x2 x3 lambda])
Lopt = subs(L,[x1,x2,x3,lambda],[s.x1,s.x2,s.x3,s.lambda])
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!