Next: About this document ...
Up: Labs and Projects for
Previous: Labs and Projects for
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.
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(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
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]);
> 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);
> 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.
Christine Marie Bonini