finding the maxima/minima using lagrange mutlipliers
    5 views (last 30 days)
  
       Show older comments
    
    Ikenna Iwudike
 on 2 Apr 2022
  
    
    
    
    
    Edited: David Goodmanson
      
      
 on 3 Apr 2022
            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 Comment
  John D'Errico
      
      
 on 2 Apr 2022
				
      Edited: John D'Errico
      
      
 on 2 Apr 2022
  
			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?
Accepted Answer
  David Goodmanson
      
      
 on 3 Apr 2022
        
      Edited: David Goodmanson
      
      
 on 3 Apr 2022
  
      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 Comments
More Answers (0)
See Also
Categories
				Find more on Assumptions in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!