How can I solve a Lagrange equation?

32 次查看(过去 30 天)
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.

采纳的回答

Torsten
Torsten 2022-10-19
编辑:Torsten 2022-10-19
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])
s = struct with fields:
x1: 33/7 x2: 19/7 x3: 18/7 lambda: -18/7
Lopt = subs(L,[x1,x2,x3,lambda],[s.x1,s.x2,s.x3,s.lambda])
Lopt = 

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by