Subsections

# Lab 3: Displaying functions of two variables

## Background

The graph of a function of a single real variable is a set of points (x,f(x)) in the plane. Typically, the graph of such a function is a curve. For functions of two variables, the graph is a set of points  (x,y,f(x,y)) in three-dimensional space. For this reason, visualizing functions of two variables is usually more difficult.

One of the most valuable services provided by computer software such as Maple is that it allows us to produce intricate graphs with a minimum of effort on our part. This becomes especially apparent when it comes to functions of two variables, because there are many more computations required to produce one graph, yet Maple performs all these computations with only a little guidance from the user.

Two common ways of representing the graph of a function of two variables are the surface plot and the contour plot. The first is simply a representation of the graph in three-dimensional space. The second, draws the level curves f(x,y)=C for several values of C in the x,y -plane. We will explore how to produce these kinds of graphs in Maple, and how to use the graphs to study the functions.

## Maple Commands, with Examples

You can define functions of more than one variable in much the same way as you defined functions of a single variable:

> f := (x,y) -> x^2 + y^2;
> f(3,-1);
> g := (a,b,c,d,e) -> a*b^2 - sin(c+d)/e;


The following commands are useful for working with functions of two variables in Maple.

• plot3D This command generates a surface plot of the function.
> plot3d(x^2-y^2, x=-1..1, y=-1..1);
> f := (x,y) -> x/2 - y + 3;
> plot3d(f, 0..2, -1..1);

The default viewing angle is from a direction 45 degrees between the positive x- and positive y- axes, and an angle of elevation of 45 degrees. You can change this viewing angle with the orientation option, orientation=[a,b]. The first number is the polar angle, measured counterclockwise from the positive x-axis. The second number is the angle of elevation; it is measured downward from straight above, also in degrees.

You can also select a viewpoint using the mouse. Click the mouse on a three-dimensional graph, and notice the toolbar that appears below the window. Click the graphic again, and the graph is replaced by a box. Hold down the button as you move the mouse, and you'll see the box from different angles. You'll also see the numbers on the left, labeled and , change accordingly. They correspond to the two numbers in the orientation option.

Once you've selected the desired viewpoint, redraw the graphic by pressing the button marked R' at the right end of the toolbar.

The other buttons in the toolbar control other aspects of how the plot is drawn.

The number of grid points in the plot can be changed with the grid=[x,y] option. You may want to increase the number of grid points if your plot appears rough, or has a lot of oscillation; you may want to use a smaller number if the function is reasonably smooth and you want to shorten calculation times.

> plot3d(x^2-y^2,x=-1..1,y=-1..1,orientation=[45,45]);
> plot3d(x^2-y^2,x=-1..1,y=-1..1,orientation=[45,20]);
> plot3d(x^2-y^2,x=-1..1,y=-1..1,orientation=[45,-45]);
> plot3d(x^2-y^2,x=-1..1,y=-1..1,orientation=[110,45]);
>
> plot3d(x^2-y^2,x=-1..1,y=-1..1,grid=[10,10]);
> plot3d(x^2-y^2,x=-1..1,y=-1..1,grid=[25,40]);

For more information on options, you can type ?plot3d,option
• contourplot Generates a contour plot of a function of two variables. This command is part of the plots'' package, so you need to run with(plots) before using the command. The basic syntax is the same as for plot3d.
> with(plots):
> contourplot(x^2-y^2,x=-1..1,y=-1..1);
> f := (x,y) -> x/2 - y + 3;
> contourplot(f,0..2,-1..1);

Maple's default is to produce eight contours. This can be changed using the option contours=n. Maple chooses the z-levels of the contours automatically. If you want to see specific level curves, you can write the z-values in a list.
> contourplot(x^2-y^2,x=-2..2,y=-2..2);
> contourplot(x^2-y^2,-2..2,-2..2,contours=6);
> contourplot(x^2-y^2,x=-2..2,y=-2..2,contours=[6]);
> contourplot(f,-2..2,-2..2,contours=[-1,0,1,2]);

• Partial derivatives. Recall that there are two ways of taking derivatives in single-variable calculus: for functions, there is the D command; for expressions, there is the diff command.
> f := x -> 2*x^2;
> D(f)(x);
> D(f)(3);
>
> diff(2*x^2,x);
> subs(x=3,diff(2*x^2,x));
> diff(f(x),x);

The same two commands can be used to take partial derivatives. Note that for the command D, variables are specified by number: thus, D[1] indicates differentiation with respect to the first variable, D[2] the second, and so on.
> f := (x,y) -> 2*x^2*y;
> D[1](f)(x,y);
> D[2](f)(x,y);
> D[1](f)(3,-1);
>
> diff(2*x^2*y,x);
> subs({x=3,y=-1},diff(2*x^2*y,x));
> diff(2*x^2*y,x,y);
> diff(2*x^2*y,x$2); > diff(f(x,y),x$2);

• TanPlane The CalcP package contains a command for calculating the tangent plane to a surface of the form z=f(x,y) at a point. To find the plane tangent to z = x2-2y2 at the point (2,3), you can use the following command:
> with(CalcP):
> TanPlane(x^2 - 2*y^2, x=2, y=3);
`
This tells you that an equation for the tangent plane is z=14+4x-12y.

## Exercises

1.
Consider the function

and let P be the point (2,3,5).
(a)
Find the partial derivatives of f with respect to x, y, z and then evaluate them at the point P.
(b)
Find the equation of the tangent plane to the surface f(x,y,z) = 3 at the point P.

2.
A group of oceanographers is mapping the ocean floor to assist in the recovery of a sunken ship. Using sonar, they develop the model

where D is the depth and x and y are the distances in kilometer.
(a)
Graph the surface of the function D.
(b)
Plot at least 10 contours of the function D and note the values of D at these contours.

(c)
What is the depth of the ship if it is located at the coordinate x=1, y = 0.5 ?

(d)
Determine the steepness of the ocean floor in the positive x-direction and positive y-direction from the position of the ship.

(e)
Find as accurately as you can the location of the shallowest and deepest point of the ocean floor in the region .