Lagrange Goes Skateboarding: How High Does He Go?

Introduction

OBJECTIVE: Learn how to maximize or minimize a function subject to a set of constraints using Mathematica.

How do you maximize or minimize a function subject to constraints? The skateboarder from the directional derivative project returns, and this time it's Lagrange himself. He will use his multipliers to determine precisely where along the figure-8 he reaches the high and low points of the surface. You will also investigate the role of the directional derivative.

Technology Guidelines

NOTE:  If you have just finished a module, restart Mathematica or Quit Kernel under the Evaluation pull-down menu before executing a new module.
TO OPEN CELLS, click on the arrow to the left of the cell or put your cursor on the right cell bracket and double click. To open all cells, highlight the bracket on the far right and select Grouping under the Cell pull-down menu and select Open All Subgroups.
TO STOP AN EXECUTION
Select the Evaluation pull-down menu and click on Abort Evaluation.
ORDER OF EXECUTION
Execute cells in the order given. Do not skip any Input cells within a given notebook.
SAVING NOTEBOOKS
You can save anytime to any directory you choose, and it is wise to save often. However, before you do your final save to reduce the size of your file, it is a good idea to delete all your output by selecting the Delete All Output selection under the Cell pull-down menu.
EXPERIENCING MAJOR PROBLEMS
Save if appropriate, then shut down Mathematica and start it up again.

Part I: Revisiting the Skateboarder Problem

The Figure-8 Path

In the project on the directional derivative, you looked at the rate of change of the height of a skateboarder who was tracing out a figure-8 on different surfaces. For this project, you will use the method of Lagrange multipliers to determine the points on the figure-8 path where the skateboarder's height reaches a maximum or a minimum. Then, you will revisit the graph of the directional derivative to help you interpret the results.

This function is best analyzed in rectangular coordinates; therefore, we will define position, velocity, and unit tangent vectors parametrically in x and y. To show the direction of movement along the figure-8, we place arrows on the graph, which requires reading in a special graphics arrow package. Remember that you must read in the package before you execute a command within the package. The package should be read in only once during a worksession.

Clear[x,y,t,f]
x1[t_]=16 ((Sin[t])^2) Cos[t];
y1[t_]=16 ((Sin[t])^3);
pp8=ParametricPlot[{x1[t],y1[t]},{t,0,2 π},AspectRatio->Automatic,PlotStyle->RGBColor[1,0,0],AxesLabel->{"x","y"},Epilog->{Arrow[{{x1[1],y1[1]},{x1[1.1`],y1[1.1`]}}],Arrow[{{x1[2.5`],y1[2.5`]},{x1[2.6`],y1[2.6`]}}],Arrow[{{x1[4],y1[4]},{x1[4.1`],y1[4.1`]}}],Arrow[{x1[5.5`],y1[5.5`]},{x1[5.6`],y1[5.6`]}]}]

The Ramp

First, we look at the three-dimensional plot and contour plot of the ramp, both showing the figure-8. Can you estimate the points of maximum and minimum height, even before you solve the problem analytically?

Clear[x,y,t]
ramp[x_,y_]=0.1` x+0.2` y;
p8ramp=ParametricPlot3D[{x1[t],y1[t],ramp[x1[t],y1[t]]},{t,0,2 π},ColorFunction->Function[{x,y,z},RGBColor[1,0,0]],AxesLabel->{x,y,z},DisplayFunction->Identity];
pramp=Plot3D[ramp[x,y],{x,-10,10},{y,-20,20},DisplayFunction->Identity];
Show[p8ramp,pramp,DisplayFunction->$DisplayFunction]
ctramp=ContourPlot[ramp[x,y],{x,-10,10},{y,-20,20},ContourShading->False,DisplayFunction->Identity];
Show[pp8,ctramp,DisplayFunction->$DisplayFunction]

You Try It: Part I

Recall the bowl surface we explored in the directional derivative module. Now we will look at it again to estimate the locations where the skateboarder reaches the high and the low points.

bowl[x_,y_]=0.02 (x^2)+0.05 (y^2);
p8bowl=ParametricPlot3D[{x1[t],y1[t],bowl[x1[t],y1[t]]},{t,0,2 π},ColorFunction->Function[{x,y,z},RGBColor[1,0,0]],AxesLabel->{x,y,z},DisplayFunction->Identity];
pbowl=Plot3D[bowl[x,y]-0.1`,{x,-10,10},{y,-20,20},AxesLabel->{x,y,z},DisplayFunction->Identity];
Show[pbowl,p8bowl,DisplayFunction->$DisplayFunction]
ctbowl=ContourPlot[bowl[x,y],{x,-10,10},{y,-20,20},ContourShading->False,DisplayFunction->Identity];
Show[ctbowl,pp8,DisplayFunction->$DisplayFunction]

As we noted in the directional derivative module, the surface is plotted just under where it should be so that the figure-8 shows up on top of it. 

From the geometry of the problem, indicate where you will reach the high and low points along the figure-8 inside the bowl.

Part II: Applying the Method of Lagrange Multipliers

The figure-8 will be our constraint function, we will need to write it in non-parametric form. This is not a trivial step. You cannot eliminate the parameter t in many parametric expressions. For this figure-8, however, we can eliminate t, and the Cartesian form of the path can be written as  ((x^2)+ (y^2)) 3 - (((4y))^4)= 0.
The surfaces we consider are the ramp and the elliptical paraboloid (bowl). We will define the gradient in the usual fashion here.

eight[x_,y_]=((((x^2)+(y^2)))^3)-(((4y))^4);
gradient[f_]:={D[f,x],D[f,y]}

Next, we set the gradient of the surface function equal to a product of a parameter, λ, times the gradient of the constraint function, and we also require that the constraint be satisfied.

Clear[x,y,λ]
solutionramp=Solve[{gradient[ramp[x,y]]==λ gradient[eight[x,y]],
               eight[x,y]==0},
{x,y,λ}]

The solutions you just found are summarized in the table below where we indicate the x, y, and z coordinates of the critical points.

results=Table[{solutionramp[[i,2,2]],solutionramp[[i,3,2]],ramp[solutionramp[[i,2,2]],solutionramp[[i,3,2]]]},{i,1,Length[solutionramp]}];
display=PrependTo[results,{"x","y","z"}]//TableForm

Contrast the values you find here to the values for x and y we found in the directional derivative module that occur when the directional derivative is 0.

({{"x", "y", "z"}, {-1.38986303224366981`, 0.440065091871244629`, -0.0509732848501180413`}, {-2.44066186681993224`, -15.416805309487529`, -3.32742724857949889`}, {2.44066983108720947`, 15.4168013273632897`, 3.32742724858137872`}, {1.38986303045863547`, -0.440065090978727546`, 0.0509732848501180235`}})

What is the connection?

Using the results above, identify the points on the contour and surface plots below that represent a maximum or minimum.

Show[pp8,ctramp,DisplayFunction->$DisplayFunction]
Show[p8ramp,pramp,DisplayFunction->$DisplayFunction]

What do you notice about the slope of the contours compared to the slope of the figure-8 curve at the critical points? What do these slopes have to do with the gradients? 
Sketch the gradient of the ramp and of the figure-8 at both the critical points and a few other points. What do you notice?

You Try It: Part II

Now, follow the same steps for the bowl-shaped surface. Find all the values of {x,y}  that make the gradient of the bowl equal to a multiple (λ) of the gradient of the figure-8 constraint. When you execute this command, you may get a warning that the Solve command may not have given all solutions, however, it gives all the real solutions that you need here.

Clear[x,y,λ]
solutionbowl=Solve[{gradient[bowl[x,y]]==λ gradient[eight[x,y]],eight[x,y]==0},{x,y,λ}]

You can extract the solutions above and determine the z-coordinate on the bowl at each of these points.

resultsbowl=Table[{solutionbowl[[i,2,2]],solutionbowl[[i,3,2]],bowl[solutionbowl[[i,2,2]],solutionbowl[[i,3,2]]]},{i,2,Length[solutionbowl]}];
PrependTo[resultsbowl,{0,0,0}];
displaybowl=PrependTo[resultsbowl,{"x","y","z"}]//TableForm

Again, let's contrast this to the results we found with the directional derivative.

({{"x", "y", "z"}, {-0.0000104272856113163592`, 8.41777135112082852`*^-9, 2.17456924734303047`*^-12}, {-2.93905524917370541`*^-15, -16.0000000000000008`, 12.8000000000000024`}, {1.57619399585851667`*^-6, 15.9999999999997655`, 12.799999999999676`}})

Identify the points on the contour plot and surface plot that resulted in a maximum or minimum.

Show[pbowl,p8bowl,DisplayFunction->$DisplayFunction]
Show[ctbowl,pp8,DisplayFunction->$DisplayFunction]

What do you notice about the slope of the contours compared to the slope of the figure-8 curve at the critical points? What do these slopes have to do with the gradients?
Sketch the gradient of the ramp and of the figure-8 at both the critical points and a few other points. What do you notice?

You Try It: Take a Ride on a Roller Coaster

Select a surface of your own. 
Check out the following roller coaster in the form of a cubic.

parx[t_]=16 ((Sin[t])^2) Cos[t];
pary[t_]=16 ((Sin[t])^3);
path[x_,y_]:=((((x^2)+(y^2)))^3)-(((4 y))^4)
rc[x_,y_]=(x^3);
p8rc=ParametricPlot3D[{parx[t],pary[t],rc[parx[t],pary[t]]},{t,0,2 π},ColorFunction->Function[{x,y,z},RGBColor[1,0,0]],AxesLabel->{x,y,z},DisplayFunction->Identity];
prc=Plot3D[rc[x,y]-10,{x,-10,10},{y,-20,20},AxesLabel->{x,y,z},PlotRange->All,DisplayFunction->Identity];
Show[prc,p8rc,DisplayFunction->$DisplayFunction]
ctrc=ContourPlot[rc[x,y],{x,-10,10},{y,-20,20},ContourShading->False,DisplayFunction->Identity];
Show[pp8,ctrc,DisplayFunction->$DisplayFunction]

Clear[x,y]
solutionrc=Solve[{gradient[rc[x,y]]==λ gradient[eight[x,y]],eight[x,y]==0},{x,y,λ}]//N

The z-coordinates on the roller coaster that correspond to these x- and y-coordinates are determined.

rc[x,y]/.solutionrc

How many critical points do you have? Locate these points on your contour and surface plots to determine which represent maximums or minimums.