User Tools

Site Tools


gibson:teaching:fall-2014:math445:lecture16-diary

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gibson:teaching:fall-2014:math445:lecture16-diary [2014/11/18 07:23]
gibson
gibson:teaching:fall-2014:math445:lecture16-diary [2014/11/18 07:25] (current)
gibson [surf, surfc]
Line 11: Line 11:
   * axis (equal, tight)   * axis (equal, tight)
   ​   ​
-====== meshgrid: ​======+===== meshgrid: =====
  
 The ''​meshgrid''​ function is essential for Matlab'​s 3D graphics. Meshgrid creates 2D arrays of x,y data covering the x,y, plane, over which a function can be evaluated and graphed. Example: The ''​meshgrid''​ function is essential for Matlab'​s 3D graphics. Meshgrid creates 2D arrays of x,y data covering the x,y, plane, over which a function can be evaluated and graphed. Example:
Line 48: Line 48:
 It is conventional to use capital letters (X,Y) for the matrix output of meshgrid from small letter (x,y) vector inputs. Observe how the output matrices X varies left to right, along the x axis, and Y varies up and down, along the y axis. Together they provide x,y, coordinates for a grid of points on the x,y plane in the region $-2 \leq x \leq 2$, $-3 \leq y \leq 3$. It is conventional to use capital letters (X,Y) for the matrix output of meshgrid from small letter (x,y) vector inputs. Observe how the output matrices X varies left to right, along the x axis, and Y varies up and down, along the y axis. Together they provide x,y, coordinates for a grid of points on the x,y plane in the region $-2 \leq x \leq 2$, $-3 \leq y \leq 3$.
    
-We can then evaluate a function ​%z = f(x,y)$ over that 2D array via elementwise matrix operations. For example, this Matlab code would evaluate ​%z = f(x,y) = x^2 + y^2$+We can then evaluate a function ​$z = f(x,y)$ over that 2D array via elementwise matrix operations. For example, this Matlab code would evaluate ​$z = f(x,y) = x^2 + y^2$
  
 <code matlab> <code matlab>
Line 89: Line 89:
 The previous plots were all looking straight down at the (x,y) plane, with the value of z = f(x,y) encoded as a color. The ''​surf''​ function will plot z = f(x,y) in 3D, as a surface of height z over the (x,y) plane. ​ The previous plots were all looking straight down at the (x,y) plane, with the value of z = f(x,y) encoded as a color. The ''​surf''​ function will plot z = f(x,y) in 3D, as a surface of height z over the (x,y) plane. ​
  
 +<code matlab>
 surf(X,Y,Z) % draw z=f(x,y) as a surface over x,y surf(X,Y,Z) % draw z=f(x,y) as a surface over x,y
 xlabel('​x'​);​ ylabel('​y'​);​ zlabel('​z'​) xlabel('​x'​);​ ylabel('​y'​);​ zlabel('​z'​)
 axis equal; axis tight axis equal; axis tight
 +</​code>​
  
 It's also possible to draw more complicated surfaces (surfaces that are not simple graphs of the form It's also possible to draw more complicated surfaces (surfaces that are not simple graphs of the form
Line 116: Line 118:
  
  
-% quiver plot 
-% used to show vector fields 
-load y.asc 
-load x.asc 
-load vx.asc 
-load vy.asc 
-clf() 
-quiver(x,​y,​vx,​vy); ​ 
-axis equal 
-axis tight 
-xlabel('​x'​);​ ylabel('​y'​);​ 
-title('​vector field vx,vy over plane x,y') 
- 
- 
-% subplots 
-% make an array of plots within a figure window 
-clf() 
-subplot(2,​2,​1) % 1st subplot in 2 x 2 array 
-quiver(x,​y,​vx,​vy);​ 
-axis equal 
-axis tight 
-subplot(2,​2,​2) % 2nd subplot in 2 x 2 array 
  
-surfc(X,​Y,​Z,​C);​ axis equal 
-subplot(2,​2,​3) % 2nd subplot in 2 x 2 array 
-surf(X,​Y,​Z,​Z);​ axis equal 
-subplot(2,​2,​4) % 4th 
-x = linspace(0,​pi,​20);​ 
gibson/teaching/fall-2014/math445/lecture16-diary.1416324207.txt.gz · Last modified: 2014/11/18 07:23 by gibson