Lagrange Multiplier Experiments with Level Curves

> with(linalg): with(plots):

Lagrange Multipliers and Level Curves

We want to find the max and min of f(x,y)=x^3+x*y+2*y^3 on the constraint set

g(x,y)=x^2+x*y+y^2-1=0.

First below is a picture of the constraint set.

Remember we only care about the values of f(x,y) on the ellipse pictured below.

> g:=x^2+x*y+y^2-1;
gr0:=implicitplot(g=0,x=-2..2,y=-2..2,thickness=2,color=black):
display(gr0);

Can you make a rough guess about where on the above ellipse x^3+x*y+2*y^3 would be biggest?

(e.g. Which quadrant? Closer to the x-axis or y-axis? About what might the maximum value be?)

Below are some level curves of f(x,y)=x^3+x*y+2*y^3 superimposed.

Look near the point (0,1) on the top level curve where f(x,y) is 2.
If you move a little to the right of (0,1)
on the ellipse , will f be bigger or smaller than 1?
How about if you move a little to the left of (0,1)?

What does this say about the possibility that (1,0) might be a constrained local maximum of f restricted to the ellipse?

Roughly which way are the gradients of f and g pointing at (1,0)? (You can read this from the picture...)

Could they be parallel at that point?

Harder but the key to Lagrange Multipliers:

Can you link the non-parallelism of the gradients at (1,0) to (1,0) not being a constrained local maximum?

> f:=x^3+x*y+2*y^3;
gr1:=contourplot(f,x=-2..2,y=-2..2,contours=[-2,1.5,2],coloring=[red,green,blue],thickness=2):
display([gr0,gr1],scaling=constrained);

Try and adjust the contours values (you can add more), so that one of the level curves is tangent to the ellipse.

You can click on the tangency spot with your mouse and look in the upper left to read the point (x,y) more accurately.

Or select Plot Display->Windows from the Options menu for bigger plots.

How many level curves with points of tangency can you find? (We found at least 4...)

From the Lagrange Multipliers point of view, each of these is a possible constrained local minimum or maximum.

What do you think are the biggest and smallest values of f on the ellipse?

> gr2:=contourplot(f,x=-2..2,y=-2..2,contours=[-2,1.5,2],coloring=[red,green,blue,violet],thickness=2):
display([gr0,gr2],scaling=constrained);

Partial Derivatives.

> f_x:=diff(f,x);
f_y:=diff(f,y);
g_x:=diff(g,x);
g_y:=diff(g,y);

You can use numerical solution routines to search for solutions.

(The second form of the command seeks solutions in a certain range.)

> sol1:=fsolve({f_x=lambda*g_x,f_y=lambda*g_y,g=0},{x,y,lambda});
sol2:=fsolve({f_x=lambda*g_x,f_y=lambda*g_y,g=0},{x,y,lambda},{x=-0.5 .. 0.5,y=0..2});

These lines evaluate f at the points found above.

Can you compare these to the values of f you found for the level curves which were tangent?

> subs(sol1,f); subs(sol2,f);

>