Finding minimum/maximum of function using Lagrange multipliers
古いコメントを表示
As mentioned in the title, I want to find the minimum / maximum of the following function with symbolic computation using the lagrange multipliers.
f(x,y) = x*y under the constraint x^3 + y^4 = 1.
syms x y lambda
f = x * y;
g = x^3 + y^4 - 1 == 0; % constraint
L = f + lambda * lhs(g); % Lagrange function
dL_dx = diff(L,x) == 0; % derivative of L with respect to x
dL_dy = diff(L,y) == 0; % derivative of L with respect to y
dL_dlambda = diff(L,lambda) == 0; % derivative of L with respect to lambda
system = [dL_dx; dL_dy; dL_dlambda]; % build the system of equations
[x_val, y_val,lambda_val] = solve(system, [x y lambda], 'Real', true) % solve the system of equations and display the results
results_numeric = double([x_val, y_val, lambda_val]) % show results in a vector of data type double
>>results_numeric =
0.8298 0.8091 -0.3917
0.8298 -0.8091 0.3917
I tried approaching this with the matlab documentation on lagrange but only got so far. This does not represent my minimum/maximum, does it? Also is there a way to now differentiate between max and min? I know there is another aproach using fmincon, which is way easier, but I want to solve it this way.
2 件のコメント
Borjan Trajanoski
2020 年 5 月 23 日
Sen XU
2021 年 4 月 9 日
Sorry, I tried the code and use Matlab version of 2014a, however, I got empty matrix as follows:
x_val =[ empty sym ]
results_numeric = Empty matrix: 1-by-0
Could you help me solve this problem.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!