Welcome
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

 Contents: Objectives Packages in this lab Gradient and critical points Commands:gradplot Examples:

#### 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 vector of a function at a point is an arrow (vector) originating at . 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 . 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 . 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:=2*x^2+3*y^2;

display(gp);

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:

display(gp);

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

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 . 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({
contourplot(f,x=1..2,y=-0.5..0.5,contours=15)
},scaling=CONSTRAINED);

Note that at the points of the -axis, the gradient vector points along the axis, and you cross a lot of level curves moving in the -direction. Not so in the -direction, you hardly cross any level curves at all This means that near the -axis the function is much more sensitive to changes in the variable than in the variable. Also note that the gradient vectors are perpendicular to the level curves. This should not be a surprise: the rate of change of along the level curve is zero, and since the rate of change of 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 must be . 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({
contourplot(f,x=1..2,y=-0.5..0.5,contours=15)
});

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

#### Example 2 — Local Minimum and Saddle:

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

display(gp);

From the picture of the gradient vector field we can see that there are two critical points of in the domain of the consideration. It looks like they are both located on the -axis. One point, let us call it , is near , and since gradient vectors point away from this point, we see that is a local minimum (as in Example 1). Another critical point, , is located near , and the behavior near this point is different. Along the -axis, gradient vectors point towards (as if is a local maximum), but along the vertical line passing through gradient vectors point away from (as if is a local minimum). So we see that 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);

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

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

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

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 and . Since we know that at a critical point , we can use Maple to find the exact location as follows.

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

Since solutions are not rational numbers, Maple displays the result in a bit funny form. It means that -coordinates of the critical points are solutions of the quadratic equation . 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(%);

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({
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]);

#### Example 3 — Monkey Saddle:

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

display(gp);

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

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({
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]);

#### Example 4 — Parabolic Cylinder:

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

display(gp,scaling=CONSTRAINED);

In this example there is a whole line of critical points given by the equation (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);

The next plot shows why the graph of is 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({