LagMultExp.mws

Lagrange Multiplier Experiments with Level Curves

> with(linalg): with(plots):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the name changecoords has been redefined

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);

g := x^2+x*y+y^2-1

[Maple Plot]

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);

f := x^3+x*y+2*y^3

[Maple Plot]

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);

[Maple Plot]

Partial Derivatives.

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

f_x := 3*x^2+y

f_y := x+6*y^2

g_x := 2*x+y

g_y := x+2*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});

sol1 := {lambda = -.4609916113, x = -.6639429568, y...

sol2 := {lambda = 3.858087636, x = -.3668329872, y ...

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);

-.1997273909

2.433687525

>

>