User Tools

Site Tools


gibson:teaching:spring-2016:math445:lecture:graphics3d

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:spring-2016:math445:lecture:graphics3d [2016/03/29 08:54]
gibson
gibson:teaching:spring-2016:math445:lecture:graphics3d [2016/03/29 09:02] (current)
gibson [Math 445 lecture 16: 3D graphics]
Line 1: Line 1:
-====== Math 445 lecture 16: 3D graphics ======+====== Math 445 lecture 16: 2D, 3D graphics ======
  
 +Some examples of plotting 2d functions $f(x,y)$ in Matlab.
  
 ---- ----
Line 71: Line 72:
 \end{eqnarray*} \end{eqnarray*}
  
 +Here's the Matlab code to make a contour plot of $f(x,y)$ with its gradient superimposed as a quiver plot.
 +
 +<file matlab plotgradient.m>​
 +% Plot f(x,y) = x e^(-x^2 - y^2) with contours and its gradient as arrows.
 +x = linspace(-2,​ 2, 30);
 +y = linspace(-2,​ 2, 30);
 +
 +[X,Y] = meshgrid(x,​y);​
 +
 +F = X .* exp(-X.^2 - Y.^2); ​ % evaluate f(x,y) on mesh
 +contour(x,​y,​F); ​             % draw contour plot of f
 +
 +% let dfdy = y component of grad F = df/dy
 +
 +dfdx = (1-2*X.^2) .* exp(-X.^2 - Y.^2); % evaluate dfdx on mesh
 +dfdy = -2*X.*Y .* exp(-X.^2 - Y.^2); ​   % evaluate dfdy on mesh
 +
 +hold on
 +quiver(x,​y,​dfdx,​dfdy); ​      % draw quiver plot
 +
 +xlabel('​x'​)
 +ylabel('​y'​)
 +title('​f(x,​y) = x e^{-x^2 - y^2} with \nabla f arrow plot')
 +colorbar()
 +</​file>​
 +
 +{{ :​gibson:​teaching:​spring-2016:​math445:​lecture:​quiver.png?​direct&​500 |}}
gibson/teaching/spring-2016/math445/lecture/graphics3d.1459266858.txt.gz ยท Last modified: 2016/03/29 08:54 by gibson