필터 지우기
필터 지우기

How can I solve a Lagrange equation?

조회 수: 12 (최근 30일)
Sena
Sena 2022년 10월 19일
편집: Torsten 2022년 10월 19일
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 = 
  댓글 수: 1
Sena
Sena 2022년 10월 19일
Thank you so much for your answer, it helped a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by