finding the maxima/minima using lagrange mutlipliers

4 次查看(过去 30 天)
I was told to Find (numerically) the location and value of the absolute maximum and minimum of the function f(x, y) = e^x − sin y on the ellipse g(x, y) = x^2 + 3*y^2 = 1 using lagrange multipliers. Then check my answer by drawing a picture illustrating that the maximum and minimum occur where the level curves of f are tangent to the ellipse. I was able to find the minimum, but I'm having trouble with the absolute maximum. Here's what I have so far:
syms x y lambda
f = exp(x) - sin (y);
g = x^2 + 3*y^2 - 1 == 0;
L = f - lambda * lhs(g);
dL_dx = (diff(L,x) == 0);
dL_dy = (diff(L,y) == 0);
dL_dlambda = (diff(L,lambda) == 0);
system = [dL_dx; dL_dy; dL_dlambda];
[x_val, y_val, lambda_val] = solve(system, [x y lambda], 'Real', true);
results_numeric = double([x_val, y_val, lambda_val])
fmin= exp(-0.6893) - sin(0.4183)
  1 个评论
John D'Errico
John D'Errico 2022-4-2
编辑:John D'Errico 2022-4-2
When you insert a picture of your code, then for someone to help you, they need to retype ALL of your code from scratch. Worse, the picture you inserted, is fuzzy, and difficult to read.
Given that you can more easily paste in the actual code directly into the question (Just use the code formatting icons on top of the box to format the code, is there a good reason why you want to make it more difficult for someone to answer you? Is that really your goal here?

请先登录,再进行评论。

采纳的回答

David Goodmanson
David Goodmanson 2022-4-3
编辑:David Goodmanson 2022-4-3
Hi Ikenna,
Here is one way. If you plot the function on the ellipse
th = linspace(0,2*pi,1000);
xx = cos(th);
yy = sin(th)/sqrt(3);
ff = (exp(xx) - sin (yy));
plot(th,ff)
you will see that ff does not cross through zero. So 1/f is bounded. If the laplace method likes finding minimums, you can get the maximum of f by finding the minimum of 1/f :
syms x y lambda
finv = 1/(exp(x) - sin (y));
g = x^2 + 3*y^2 - 1 == 0;
L = finv - lambda * lhs(g);
dL_dx = (diff(L,x) == 0);
dL_dy = (diff(L,y) == 0);
dL_dlambda = (diff(L,lambda) == 0);
system = [dL_dx; dL_dy; dL_dlambda];
[x_val, y_val, lambda_val] = solve(system, [x y lambda], 'Real', true)
results_numeric = double([x_val, y_val, lambda_val])
fmax = (exp(x_val) - sin(y_val))
fmax = 2.7792862671716761949017792501582

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by