Advanced Lagrange Multipliers

Department of Mathematics, Statistics, and Computer Science

University of Illinois at Chicago

Copyright © 1998 Paul Brown, Heidi Burgiel, Marc Culler



Introduction

In this lab you will use Maple to look at the method of Lagrange Multipliers from a graphical point of view. We will analyze several examples which illustrate most of the different situations that can arise. (Some of these situations rarely arise in textbook problems -- hence the word "advanced" in the title. They are, however, easily understood graphically.) We will create some simple Maple tools to generate the pictures that we will need for this analysis.

The Lagrange Equations

This section is a quick discussion of the mathematical ideas that we will study in this lab.

We will consider a constrained extremum problem in 2 variables. As you know, this means that we are given a constraint equation of the form g(x,y)=0 and a function f(x,y). The problem is to find the largest and smallest values of f(x,y), with the restriction that the point (x,y) must be a solution of the constraint equation g(x,y)=0.

There is a very important assumption, which is often forgotten, but which must hold in order for the method of Lagrange Multipliers to work. This assumption is that the gradient of g must not be 0 at any point (x,y) where g(x,y)=0. The point of this assumption is that it implies that the solution of the constraint equation will be a curve (or possibly several curves).

To visualize a typical constrained extremum in three dimensions, you could imagine hiking along the graph of the function f, following a path which lies directly above the curve g(x,y)=0 (or directly below, when f(x,y) is negative). As you reach your highest elevation you are standing on a certain contour line on the graph. Your path cannot cross this line; if it did you would not have reached your highest elevation. Your path must be tangent to the contour line at the highest point. Here is a picture, showing your path in red. Notice how the path is tangent to the contour at the highest point.

A 2-dimensional picture can actually be more informative. To visualize a typical contrained extremum in terms of a contour map, you can imagine that the function f(x,y) represents the temperature at the point (x,y). We can imagine walking along the curve g(x,y) =0 carrying a thermometer. (This is a curve because of the assumption above.) Suppose we find that the temperature reaches a maximum value of T at a certain point P on this curve. Typically, there will be another curve passing through the point P, called an isotherm, with the property that every point on the isotherm has the same temperature (which must be T for the isotherm through P). On one side of the isotherm the temperature is less than T on the other side it is more than T. Since our temperature reached a maximum of T, we must never have crossed over to the warm side of the isotherm. This can only happen if the curve g(x,y)=0 is tangent to the level curve f(x,y) = T at the point P. Another way of saying this is to say that the gradient of f is parallel to the gradient of g at the point P. In this typical situation we would find that both gradient vectors are non-zero, and grad f is a non-zero multiple of grad g.

The picture below illustrates this, using the same function and path that were used in the 3-dimensional picture.

There are other, less typical, ways in which the temperature can reach its maximum at P. These occur when P is actually a critical point of f. In this case the gradient of f is zero at P. These points still arise as solutions to the Lagrange Equations since grad f = 0 grad g. But, as you will see, it is not necessarily the case that the curve g(x,y)=0 is tangent to the isotherm at P.

Tools

All we need to visualize constrained extrema is a contour map of f with the curve g(x,y)=0 superimposed upon it. Unfortunately there are a couple of small obstacles that must be overcome to make Maple draw these pictures for us. We will define a couple of Maple functions to work around these obstacles and make Maple do what we want.

Drawing the contour map

The first obstacle we encounter is that Maple's built-in contourplot function does not draw the same kind of contour map that we have been using in Math 210. Maple's contour map is a 3-dimensional picture: the contour f(x,y)=c is drawn at height c, in the plane z=c, rather than in the x-y plane. This is a minor problem. If we view the Maple picture from above, then the 3-dimensional contour map looks the same as a regular contour map in the x-y plane. (NOTE: For those who have Maple VR5, this problem has been addressed by having two functions, contourplot and contourplot3d.)

To see what we are talking about here, open a Maple worksheet and type

> with(plots);

> f := (x,y) -> x^2 + y^2;

> contourplot(f(x,y), x=-1..1, y=-1..1);

Use your plot inspector to select "scaling=CONSTRAINED" so that the level curves are correctly drawn as round circles instead of ellipses. Now use your mouse to rotate the picture and see all of the level circles stacked up in space. It might help to select "axes=BOX" as well.

You may notice that the level curves are colored in a peculiar way which is not particularly useful. Since we will be viewing our contour maps from above, and since Maple does not put labels on the contours to indicate their level, it would be handy to have the curves colored according to their height. We can ask Maple to do this by adding the option "color=f(x,y)". This specifies that the "hue" of each level curve should be determined by the value of f on the curve, i.e. by its height. Try it:

> with(plots);

> contourplot(f(x,y), x=-1..1, y=-1..1, scaling=CONSTRAINED, axes=BOX, color=f(x,y));

It would be nice if Maple put in a few more contours (it uses 10 by default). We can make it draw 20 contours with the option "contours=20".

Now we can define a Maple function to make contour plots just the way we like them. There will be three arguments: a function, a range of x-values, and a range of y-values. (If you are using Maple VR5, replace contourplot() with contourplot3d() below.)

> m210contourplot := (f,xrange,yrange) -> contourplot(f(x,y), x=xrange, y=yrange, scaling=CONSTRAINED, axes=BOX, color=f(x,y), contours=20);

Now test out your new tool on the function f:

> m210contourplot(f,-1..1,-1..1);

Drawing the constraint curve

We would like to get Maple to superimpose the constraint curve g(x,y)=0 on our contour map. We can get Maple to draw the curve by using the implicitplot function.

> g := (x,y) -> y - 2*x^2 + 1;

> implicitplot(g(x,y)=0, x=-1..1, y=-1..1);

But here we run into a snag. The implicitplot function produces a 2-dimensional plot and the contourplot function produces a 3-dimensional plot (unless you have Maple VR5) and Maple refuses to combine 2-dimensional plots and 3-dimensional plots. We could try to solve the simultaneous equations z=0 and g(x,y)=0 to obtain a curve in the x-y plane, but implicitplot3d cannot handle two equations.

So, in order to work our way around this, We ask Maple to plot the 3-dimensional solution to g(x,y)=0. This is a surface that looks like a vertical fence through the curve g(x,y)=0 in the x-y plane. But we restrict the solution to a very thin slab containing the x-y plane. The result looks like the curve we want, although it really is a thin surface.

Here is a Maple function to draw the constraint curve of the form g(x,y)=0. There are three arguments, the function g, a range of x-values and a range of y-values. We will make the constraint curve black, so we can distinguish it from the colored contours of f.

> m210constraintplot := (g, xrange, yrange) -> implicitplot3d(g(x,y)=0, x=xrange, y=yrange, z=-0.001 .. 0.001, style=contour, color=black, grid=[25,25,2], axes=BOXED, scaling=CONSTRAINED);

Test it out on our constraint curve:

> m210constraintplot(g, -1..1, -1..1);

Combining the plots

The built-in Maple function display3d can be used to combine several plots into one. We use it to make a new Maple function to display the contour map and the constraint curve at once. There are four arguments: the function f, the function g that appears in the constraint equation g(x,y) = 0, a range of x-values, and a range of y-values. The option "orientation=[0,0]" causes Maple to draw the picture as viewed from the z-axis.

> m210lagrangeplot := (f, g, xrange, yrange) -> display3d([m210contourplot(f,xrange,yrange), m210constraintplot(g,xrange,yrange)], orientation=[0,0]);

An example

Use m210lagrangeplot to draw the contour map for f(x,y) with the constraint curve g(x,y) superimposed.

> m210lagrangeplot(f,g,-1..1,-1..1);

Look for the constrained local extrema on your picture. In this case they occur at points where the constraint curve is tangent to a contour. There is one local maximum and two local minima. These points are marked with a red square for the max and blue squares for the mins in the picture below:

Assignment

1. Use the command ?extrema to bring up a help page which explains how to get Maple to solve a constrained extremum problem by solving the Lagrange equations. Read this help page and use the extrema command to check your work in the next question. You might want to look at this example of how to use the extrema function in Maple.

2. Draw the contour map for f(x,y) and the constraint curve g(x,y)=0 in each of the following cases. In each case find the constrained local extrema and mark them on the contour map, and turn in the contour map. For extra credit, figure out how to do this without using any paper by creating an html document containing your answers. (Don't forget to tell us the URL!).

f(x,y) = x^2 + y^2 g(x,y) = y - 2*x^2 + 1
f(x,y) = x^2 + y^2 g(x,y) = y - 2*x^2 - 1
f(x,y) = y - 2*x^2 g(x,y) = x^2 + y^2 - 1
f(x,y) = y g(x,y) = y^3 - x^2
f(x,y) = x^2 - x*y + y^2 g(x,y) = x^2 + y^2 - 1
f(x,y) = x^2*y g(x,y) = x^2 + y^2 - 1
f(x,y) = (1 + 0.1*x + 2*x^2)*exp(-x^2 - y^2) g(x,y) = x^2 - 0.2*x*y + y^2-0.8
3. In which of the cases above is there an extremum at a point where the constraint curve is NOT tangent to a level curve for f? Which one of the constrained extremum problems above CANNOT be solved by the method of Lagrange Multipliers?