Azzera filtri
Azzera filtri

How can I solve a Lagrange equation?

12 visualizzazioni (ultimi 30 giorni)
Sena
Sena il 19 Ott 2022
Modificato: Torsten il 19 Ott 2022
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.

Risposta accettata

Torsten
Torsten il 19 Ott 2022
Modificato: Torsten il 19 Ott 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])
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 = 
  1 Commento
Sena
Sena il 19 Ott 2022
Thank you so much for your answer, it helped a lot.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by