Math 215 – Calculus III
WelcomeX
- Course Information
- Syllabus
- Solutions
- Maple Labs
 
- Maple Tutorial
 
- Sample Maple Session
- Lab Project 1
- Lab Project 2
- Lab Project 3
- Lab Project 4
- Lab Project 5
- triple.html
- Maple Demos
- Maple HowTo
- refcard.pdf
+ Homework
- Practice Exams
- Student's Guide
- Help!
(Off this site)
Web Homework
Math Lab
Instructor Directories
Math Careers
Student Data Sheet
Gateway

Math 215 Lab Project 3

Gradients and Rates of Change

Objectives

  • To visualize the relationship between the graph and the level sets of a function f(x,y) using the pattern of its gradient.
  • To explore the sensitivity of ceratin functions to change in their variables.

Packages in this lab

To be able to use the Maple commands described in this section, you need to load the plots package.

> with(plots):

Warning, the name changecoords has been redefined

Gradient and critical points

Gradient vector of a function fat a point P is an arrow (vector) originating at P. It always points in the direction of the greatest increase of the function, and its magnitude (length) is equal to the rate of increase in this direction. In cartesian coordinates gradient can be calculated by the formula grad(f)(P) = <diff(f,x),diff(f,y)>(P). Maple command gradplot calculates and plots gradient vectors at many different points. The resulting picture is called the picture of the gradient vector field.

The picture of the gradient vector field contains a lot of information about the function f. It is essentially the same information that is contained in the picture of the level curves, only expressed in different language. This statement will become clear as we go along.

Example 1 — Local Minimum: f(x,y) = 2*x^2+3*y^2

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

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

> gp:=gradplot(f,x=-2..2,y=-2..2):
display(gp);

[Maple Plot]

The picture above is the basic picture of the gradient. We can make its main features more visible by decreasing the number of sample points by using the grid option (the default is grid=[20,20] ), changing arrow style to THICK (the default is THIN, the remaining two are LINE and SLIM, you should try them as well), and by adding color. This is what we get:

> gp:=gradplot(f,x=-2..2,y=-2..2,arrows=THICK,grid=[15,15],color=blue):
display(gp);

[Maple Plot]

You can see that the gradient vectors point away from the origin. This menas that our function has a minimum at the origin (or somewhere near it, you can't obtain exact information from the graph, you need to use calculus for that.). Also, note that the length of the gradient vectors increases as you move further from the origin, this menas that the rate of increase of is getting bigger. Let us now combine this picture with the picture of level curves. We also arrange for the scales on both axes to be the same.

> cp:=contourplot(f,x=-2..2,y=-2..2,contours=20):
display({gp,cp},scaling=CONSTRAINED);

[Maple Plot]

Note that the large magnitude of the gradient vector corresponds to the small distances between the level curves. Both of these features correspond to the higher rate of change of f. In particular, near the origin level curves are sparse and look like ellipses, and gradient vectors look like dots (or disappear completely). This is how you can recognize a local minimum . For a local maximum , the picture is the same, but the arrows point in the oppposite direction (towards the maximum).

Let us now look at this picture away from the local minimum.

> display({
gradplot(f,x=1..2,y=-0.5..0.5,arrows=SLIM,grid=[15,15],color=blue),
contourplot(f,x=1..2,y=-0.5..0.5,contours=15)
},scaling=CONSTRAINED);

[Maple Plot]

Note that at the points of the x-axis, the gradient vector points along the axis, and you cross a lot of level curves moving in the x-direction. Not so in the y-direction, you hardly cross any level curves at all This means that near the x-axis the function is much more sensitive to changes in the x variable than in the y variable. Also note that the gradient vectors are perpendicular to the level curves. This should not be a surprise: the rate of change of falong the level curve is zero, and since the rate of change of f in any direction is equal to the scalar projection of the gradient vector to this direction, the angle between the level curve and the gradient vector at any point P must be Pi/2. Note that if we do not use the scaling=CONSTRAINED option, the angles become distorted and the level curves may not look perpendicular to the gradient vectors:

> display({
gradplot(f,x=1..2,y=-0.5..0.5,arrows=SLIM,grid=[15,15],color=blue),
contourplot(f,x=1..2,y=-0.5..0.5,contours=15)
});

[Maple Plot]

Let us now combine these two-dimensional plots with the three-dimensional graph of our function. The Maple code in this example is a bit complicated, but you do not need to use it in your lab project.

> surface:=plot3d(f,x=-2..2,y=-2..2,style=PATCHCONTOUR,contours=20):
gcp:=display({gp,cp}):
shift:=plottools[transform]((x,y)->[x,y,0]):
display({surface,shift(gcp)},
axes=BOXED,orientation=[105,45]);

[Maple Plot]

Example 2 — Local Minimum and Saddle: f(x,y) = x^3-10*x+2*y^2

> f:=x^3-10*x+2*y^2;

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

> gp:=gradplot(f,x=-2.5..2.5,y=-3..3,arrows=SLIM,color=blue):
display(gp);

[Maple Plot]

From the picture of the gradient vector field we can see that there are two critical points of f in the domain of the consideration. It looks like they are both located on the x-axis. One point, let us call it P, is near x = 1.8, and since gradient vectors point away from this point, we see thatP is a local minimum (as in Example 1). Another critical point, Q, is located near x = -1.8, and the behavior near this point is different. Along the x-axis, gradient vectors point towards Q (as if Q is a local maximum), but along the vertical line passing through Q gradient vectors point away from Q (as if Q is a local minimum). So we see that Q is a saddle. Adding the level curves to the picture confirms our conclusions.

> cp:=contourplot(f,x=-2.5..2.5,y=-3..3,contours=20):
display({gp,cp},scaling=CONSTRAINED);

[Maple Plot]

We now "zoom in" and study the plot near the critical points.

> display({
gradplot(f,x=-2.2..-1.4,y=-0.5..0.5,arrows=SLIM,color=blue),
contourplot(f,x=-2.2..-1.4,y=-0.5..0.5)
},scaling=CONSTRAINED);

[Maple Plot]

> display({
gradplot(f,x=1.4..2.2,y=-0.5..0.5,arrows=SLIM,color=blue),
contourplot(f,x=1.4..2.2,y=-0.5..0.5)
},scaling=CONSTRAINED);

[Maple Plot]

We can very clearly see that critical points are indeed a local minimum and a saddle, but we can also see that they are not exactly at x = -1.8 and x = 1.8. Since we know that at a critical point gard(f) = 0, we can use Maple to find the exact location as follows.

> solve({diff(f,x)=0,diff(f,y)=0});

{y = 0, x = RootOf(3*_Z^2-10,label = _L7)}

Since solutions are not rational numbers, Maple displays the result in a bit funny form. It means that x-coordinates of the critical points are solutions of the quadratic equation 3*x^2-10 = 0. However, you can force Maple to solve this equation for you in radicals by changing the global _EnvExplicit option . This change will be in effect until you quit Maple.

> _EnvExplicit:=true:
solve({diff(f,x)=0,diff(f,y)=0});
evalf(%);

{y = 0, x = 1/3*sqrt(30)}, {y = 0, x = -1/3*sqrt(30...
{x = 1.825741858, y = 0.}, {y = 0., x = -1.82574185...

We conclude the study of this example by combining gradient and level curves plots with the three-dimensional graph of our function. The Maple code in this example is a bit complicated, but you do not need to use it in your lab project.

> surface:=plot3d(f,x=-2.5..2.5,y=-3..3,style=PATCHCONTOUR,contours=20):
gcp:=display({
gradplot(f,x=-2.5..2.5,y=-3..3,arrows=THICK,grid=[10,10],color=blue),
contourplot(f,x=-2.5..2.5,y=-3..3,contours=20)
}):
shift:=plottools[transform]((x,y)->[x,y,-15]):
display({surface,shift(gcp)},
axes=BOXED,orientation=[105,45]);

[Maple Plot]

Example 3 — Monkey Saddle: f(x,y) = x*(x^2-y^2)

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

f := x*(x^2-y^2)

> gp:=gradplot(f,x=-1..1,y=-1..1,color=blue,grid=[30,30]):
display(gp);

[Maple Plot]

From the picture of the gradient vector field it looks like the origin is a critical point (verify that!), and that it is not a local minimum or maximum (some gradient vectors point towards the origin, and some point away from it). Let us add the level curves. To make the plot look better near the origin we increased the number of sample points. Try decreasing it by a factor of 10 if the next command takes too long to execute.

> cp:=contourplot(f,x=-1..1,y=-1..1,contours=20,numpoints=10000):
display({gp,cp},scaling=CONSTRAINED);

[Maple Plot]

Now the picture looks similar to the picture of the saddle, but it is divided into six sectors instead of four. For this reason it is called a monkey saddle , there is a room for a tail! Here is a better view (use the mouse to turn the picture around). The Maple code in this example is a bit complicated, but you do not need to use it in your lab project.

> surface:=plot3d(f,x=-2..2,y=-2..2,style=PATCHCONTOUR,contours=20):
gcp:=display({
gradplot(f,x=-2..2,y=-2..2,arrows=THICK,grid=[10,10],color=blue),
contourplot(f,x=-2..2,y=-2..2,contours=20)
}):
shift:=plottools[transform]((x,y)->[x,y,-8]):
display({surface,shift(gcp)},
axes=BOXED,orientation=[80,55]);

[Maple Plot]

Example 4 — Parabolic Cylinder: f(x,y) = (2*y-3*x)^2

> f:=(2*y-3*x)^2;

f := (2*y-3*x)^2

> gp:=gradplot(f,x=-2..2,y=-2..2,color=blue):
display(gp,scaling=CONSTRAINED);

[Maple Plot]

In this example there is a whole line of critical points given by the equation 2*y-3*x = 0 (can you explain that?). Since the gradient vector field points away from it, we see that all these critical points are minima. Here are a few more pictures.

> cp:=contourplot(f,x=-2..2,y=-2..2,contours=20): display({gp,cp},scaling=CONSTRAINED);

[Maple Plot]

The next plot shows why the graph of fis sometimes calle a trough. The Maple code below is a bit complicated, but you do not need to use it in your lab project.

> surface:=plot3d(f,x=-2..2,y=-2..2,style=PATCHCONTOUR,contours=20,view=-5..20):
gcp:=display({
gradplot(f,x=-2..2,y=-2..2,arrows=THICK,grid=[10,10],color=blue),
contourplot(f,x=-2..2,y=-2..2,contours=20)
}):
shift:=plottools[transform]((x,y)->[x,y,-4]):
display({surface,shift(gcp)},
axes=BOXED,orientation=[75,55]);

[Maple Plot]


Valid XHTML 1.0!
©2003 The Regents of the University of Michigan
Last Modified: Mon Sep 1 21:44:48 2003