finding the maxima/minima using lagrange mutlipliers
조회 수: 12 (최근 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
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!