lecture23

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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...
View Full Document

Page1 / 3

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online