surS02

advertisement
Math 2224
Sketching 3D Functions and Contours
Ê
y
ˆ
Let f (x, y)  1 cosÁ
2
2 ˜ . We will sketch the surface on the domain
Ë1 + x + y ¯
3.8 £ x £ 3.8, - 3.8 £ y £ 3.8.
Three dimensional wire mesh surface plots are drawn with the command mesh. To draw
the graph of a function z  f (x, y) , first define vectors x and y , which give partitions of
the sides of the rectangle. The function meshgrid creates this partition. When you graph
a surface, also label the x and y axes.
»[x,y]=meshgrid(-3.8:.1:3.8,-3.8:.1:3.8);z=-1+cos(y./(1+x.^2+y.^2)); mesh(x,y,z)
»xlabel('x'),ylabel('y')
0
-0.02
-0.04
-0.06
-0.08
-0.1
-0.12
-0.14
4
2
4
2
0
0
-2
y
-2
-4
-4
x
To rotate the graph to get a new viewpoint you can use the command rotate3d. After
you type this in Matlab, click on the graph, continue to hold down on the button, and then
move your mouse to change the viewpoint. (Note: In order to insert 3D graphs from
Matlab to Word, you may have to save them from Matlab as a pict or bitmap file and then
insert them into Word.)
»rotate3d
You can also use the view command to specify the viewpoint from which the threedimensional object is to be viewed. Here is Matlab’s description.
VIEW(AZ,EL) and VIEW([AZ,EL]) set the angle of the view from which an
observer sees the current 3-D plot. AZ is the azimuth or horizontal
rotation and EL is the vertical elevation (both in degrees). Azimuth
revolves about the z-axis, with positive values indicating counterclockwise rotation of the viewpoint. Positive values of elevation
correspond to moving above the object; negative values move below.
VIEW([X Y Z]) sets the view angle in Cartesian coordinates. The
magnitude of vector X,Y,Z is ignored.
Contour Plots
Contour plots, or, graphs of level curves are created using the contour function whose
syntax is contour(z). You first use meshgrid to define the grid and then define your
function z  f (x, y) . The command meshc creates the surface with the contours on the
xy plane below the surface.
»[x,y]=meshgrid(-3.8:.1:3.8,-3.8:.1:3.8);z=-1+cos(y./(1+x.^2+y.^2));
»subplot(1,2,1);contour(x,y, z),title('Contour Plot')
»subplot(1,2,2);meshc(x,y, z),title('Surface with Contours')
Contour Plot
Surface with Contours
3
0
-0.02
2
-0.04
-0.06
1
-0.08
-0.1
0
-0.12
-0.14
-0.16
-1
-0.18
-0.2
-2
4
2
-3
4
2
0
0
-2
-2
0
2
-2
-4
-4
Other options for contour plots include:
contour(z,n) tells Matlab to plot n contours
contourf(z) or contourf(z,n) plots a filled contour plot.
c=[z1, z2, …,zn]; contour(z, c) plots the specified contours in matrix c.
»contourf(x,y, z,2)
2
3
2
1
0
-1
-2
-3
-3
-2
-1
0
1
2
3
»c=[-.01,-.02,-.05,-.015]; cp = contour(x,y,z,c), clabel(cp)
-0.02
-0.015
3
-0.01
2
1
-0.05
0
-0.015
-1
-0.02
-0.05
-0.01
-2
-3
-3
-2
-1
0
1
2
3
clabel(name) labels the contours identified.
Assignment : 15 points – ________________________________.
Put a heading at the top with your name(s), your ID number(s) and “Math 2224”. Any
explanations or conclusions should be done using grammatically correct sentences and all
commands and outputs must appear for any necessary work. This lab may be done
individually or as a group of 2 people.
3


1. (9 pts.) Let f (x,y)  (y  x)e
. (In Matlab: z=(y.^3-x).*exp(-x.^2-2*y.^2);)
a. Plot the surface on the intervals 2.5 £ x £ 2.5, - 2.5 £ y £ 2.5 . Label the
coordinate axes and orient them as the text does.
b. Plot a contour map for the function on the same intervals.
c. On your computer the surface and contour lines are shades of color. What is the
color of the highest point on your surface? What is the color of the lowest point?
d. From the contour plot determine and then state approximate coordinates for the
highest point(s) on the surface and coordinates for the lowest point(s) on
2.5 £ x £ 2.5, - 2.5 £ y £ 2.5 . Evaluate the function at each of those points to
approximate the function’s maximum and minimum value.
e. Plot the contours for z = -1 and z = 1. Why did this command generate a blank
box?
 x 2 y 2
3
2.(3 pts.) Below is the contour plot of one of the surfaces we studied in 12.6. Which
surface is it? Give reasons for your answer.
3
2
1
0
-1
-2
-3
-3
-2
-1
0
1
2
3
3. (3 pts.) Below is the contour plot of a function f (x, y) . By hand, sketch the graph of
this function for 1 £ x £ 1 and - 1 £ y £ 1 using this plot.
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
4
Download