フィルターのクリア

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 Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by