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!