
%Author: Jie Zhang
%Date:    March 20, 2013
%Purpose: CDS301 class CH6: Visualize the gradient, divergence and
%vorticity
%Scalar function: a double peak 2-D Gaussian function
%Vector function: the gradient of the Gaussian 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 Gaussian function
z=x.*exp(-x.^2-y.^2);  
%surf(x,y,z)  %get the idea of the data

%display the image
hf_1=figure(1)
%hi_1=imagesc([-2.0,2.0],[-2.0,2.0],z)
hi_1=surface(x,y,z)
%get(hi_1)  %find the handle values
set(hi_1,'EdgeAlpha',0)  %remove the wireframe lines, or edge lines
set(hi_1,'FaceColor','interp')  %smooth color from the surface

colorbar  %colorbar indicates the values

%calculate the gradient
[gx,gy]=gradient(z,0.2,0.2)   %note that spaceing between points is 0.1

hf_2=figure(2)
%surf(x,y,gy)

quiver(x,y,gx,gy)

%calcuate the divergence
div=divergence(x,y,gx,gy)
hf_3=figure(3)
surf(x,y,div)

%calculate the vorticity
[curlz,cav]=curl(x,y,gx,gy)
hf_4=figure(4)
surf(x,y,curlz)
