This preview has intentionally blurred sections. Sign up to view the full version.View Full 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
This note was uploaded on 02/09/2012 for the course MATH 344 taught by Professor Young,t during the Fall '08 term at Ohio University- Athens.
- Fall '08