
%Author: Jie Zhang
%Date:    March 20, 2013
%Purpose: CDS301 class CH6: Visualize the gradient, divergence and
%vorticity
%Vector function: a given vector function
%Divergence function: divergence of the gradient
%Vorticity: the curl of the vector function

%clear the variables and figure space
clear 
clf reset

%define the domain
%x: [-2.0, 2.0], and y: [-2.0,2.0]
[x,y]=meshgrid([-2.0:0.2:2.0],[-2.0:0.2:2.0]);

%define the vector function
u=-y.*sin(x)
v=x

hf_1=figure(1)
%show the vector in glyph format
quiver(x,y,u,v)

%calcuate the divergence
div=divergence(x,y,u,v)
hf_2=figure(2)
surf(x,y,div)

%calculate the vorticity
[curlz,cav]=curl(x,y,u,v)
hf_3=figure(3)
surf(x,y,curlz)
