next up previous contents
Next: Extrema of Functions Up: Computational Labs in Mathematica Previous: Chain Rule for Partial

Gradients, Normals, Level Curves

Objectives

In this lab you will demonstrate the relationship between the gradients and level curves of functions.

The Gradient as a Vector Operator

The gradient of a function, tex2html_wrap_inline326 is a vector whose components are the partials of the original function;

displaymath324

Define the function tex2html_wrap_inline328 by

       f[x_,y_] := (x^2 + 4 y^2) Exp[1 - x^2 -y^2]
To visualize the function, you may wish to do a Plot3D or a ContourPlot,
       fcontours = ContourPlot[f[x,y], {x,-3,3}, {y,-3,3},
                               ContourShading->False,
                               PlotPoints->40];
It is easy to find the gradient in Mathematica,
       gradf = {D[f[x,y],x], D[f[x,y],y]}
What make the above result a vector, as far as Mathematica is concerned, is the presence of the `{ , }.'

Gradients and Level Curves

The gradient of a function is a vector field over the domain of the function. We can see what the above vector field looks like. First we need to load an external package for plotting vector fields. Type the following command exactly (notice that the single quotes are single left quotes),

       Needs["Graphics`PlotField`"]
and shift-return. Then try this:
       fgradplot = PlotVectorField[gradf, {x,-3,3}, {y,-3,3}];
What you should see is a plot of many vectors. The tail of each vector resides where Mathematica evaluated the gradient. Try overlaying the vector field plot with the plot of level curves of f generated above using the Show command:
       Show[fcontours, fgradplot];
You can `zoom' into some particular portion of the graph by specifying the x,y range for the plot using the PlotRange option, as follows:
       Show[fcontours, fgradplot, PlotRange->{{0, 2},{0, 2}}];

Finally

Examine the functions

displaymath334

and

displaymath335

Superpose level curves and plots of the gradient field to demonstrate that the gradient is perpendicular to the level curves of the function.



James Powell
Fri Feb 14 12:47:33 MST 1997