# lecture23 - Lecture 23 Plotting Functions of Two Variables...

This preview shows pages 1–2. Sign up to view the full content.

Lecture 23 Plotting Functions of Two Variables Functions on Rectangular Grids Suppose you wish to plot a function f ( x, y ) on the rectangle a x b and c y d . The graph of a function of two variables is of course a three dimensional object. Visualizing the graph is often very useful. For example, suppose you have a formula: f ( x, y ) = x sin( xy ) and you are interested in the function on the region 0 x 5, π y 2 π . A way to plot this function in Matlab would be the following sequence of commands: > f = inline(’x.*sin(x.*y)’,’x’,’y’) > [X,Y] = meshgrid(0:.1:5,pi:.01*pi:2*pi); > Z = f(X,Y) > mesh(X,Y,Z) This will produce a 3-D plot that you can rotate by clicking on the rotate icon and then dragging with the mouse. Instead of the command mesh , you could use the command: > surf(X,Y,Z) The key command in this sequence is [X Y] = meshgrid(a:h:b,c:k:d) , which produces matrices of x and y values in X and Y . Enter: > size(X) > size(Y) > size(Z) to see that each of these variables is a 101 × 51 matrix. To see the first few entries of X enter: > X(1:6,1:6) and to see the first few values of Y type:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern