Вы находитесь на странице: 1из 4

MATLAB assignment Math 222, Fall 2011

GRAPHING PROBLEMS!!!

Part I: A simple graph

Assignment! Problem 1: First simply plot the function y = x3 x2 + 6x sin(5x) 9x , on the interval 4 x 4. (If you cannot do this, then you need to review the intro packet that I created!)

Part II: A curve in 3-D

Time for some three dimensional graphics. Here is some MATLAB code I wrote which draws a curve in three dimensional space: % A curve in three dimensions t = [0:0.01:10*pi]; plot3(cos(t),sin(t),4*t); First save this program into an m-le and run it. Next, in the gure window above the gure click on the button with the counter-clockwise arrow. It is just to the right of the button with a hand on it. Rotate the gure into a few dierent positions so that you can see it well.

Assignment! Problem 2: Change the code to give you a look at the curve: (t) := (t cos(2t), t sin(2t), 5t), r for 0 t 12 .

Put comments into your code explaining what each line does. Print the curve from a couple of dierent angles. Submit these pictures and your code.

Part III: Surfaces

The next bit of fun. Here is some MATLAB code I wrote which draws a surface in three dimensional space: % A surface in three dimensions [x,y] = meshgrid(-3:0.05:3); z = -0.1*y + y.*exp(-x.2-y.2); mesh(x,y,z); If you cannot guess what the command meshgrid is doing (and probably even if you can), then I recommend typing: [u,v] = meshgrid(-2:0.5:2) (No semicolon here!) in the main MATLAB window. Hopefully the denition of z now makes clear the fact that I am working with the function z = .1y + yex
2 y 2

The last line which uses the command mesh is the line that draws this thing. In fact there are a zillion options when it comes to how to graph this type of function, and I recommend messing around and replacing the line where I called the mesh command with contour3(x,y,z,40); surf(x,y,z); surfc(x,y,z); or or even all of the following or

surf(x,y,z,FaceColor,green,EdgeColor,none); camlight left; lighting phong; You can learn a lot more about your options by sticking any of these commands into the search feature of the help menu. (You may certainly want to

look up meshgrid in particular so that you learn the syntax to make the x bounds dierent from the y bounds.) Assignment! Problem 3: Change the code to give you a look at any of the interesting functions in the textbook of the form z = f (x, y). (Interesting in this context means that at least two critical points should t in your picture. Also, dont choose a quadric surface.) Do this in a domain where the bounds for x are dierent from the bounds for y. (In other words, you will need to use the help menu to gure out how to use the command meshgrid.) Print your surface from at least two dierent angles, and use at least two of the commands mentioned above. Submit these pictures and your code. Write down (in pen on what you submit or in a comment within your code) which function you are graphing and on what domain you graphed it.

Now sometimes it is more convenient to plot things by using polar coordinates. Here is some code that I found online and adapted to my purposes to create graphs for the rst test: %z = x2 + y2 r=linspace(0,2,20); theta=linspace(0,2*pi,40); [r,theta]=meshgrid(r,theta); x=r.*cos(theta); y=r.*sin(theta); z=r.2; mesh(x,y,z) xlabel(x-axis) ylabel(y-axis) zlabel(z-axis) In order to understand this code one should look up linspace in the help menu, and there one will nd (amongst many other things): y = linspace(a,b,n) generates a row vector y of n points linearly spaced between and including a and b.

It seems to me as if one could simply use instead: y = [a:(b-a)/(n-1):b], but I think that the linspace command is less confusing.

Of course, many of the graphs on the rst test were not graphs of functions (they failed the vertical line test), and so I needed to use more complicated code which I also found online. For example, to graph my sphere, I used the code: % x2 + y2 + z2 = 9 r=linspace(0,3,20); theta=linspace(0,2*pi,40); [r,theta]=meshgrid(r,theta); x=r.*cos(theta); y=r.*sin(theta); z1=sqrt(9 - r.2); z2=-sqrt(9 - r.2); mesh(x,y,z1) hold on mesh(x,y,z2) xlabel(x-axis) ylabel(y-axis) zlabel(z-axis) Assignment! Problem 4: Change this last piece of code to graph the hyperboloid of two sheets determined by: z 2 = x2 + y 2 + 4 . Print it out from a few dierent angles. Submit your pictures and your code.

Assignment! Bonus Problem: Change this last piece of code to graph the hyperboloid of one sheet determined by: z 2 + 4 = x2 + y 2 . Print it out from a few dierent angles. Submit your pictures and your code. Explain your calls to linspace by putting comments into your code.

Вам также может понравиться