%EEMAG1 Fall 99
%S. Mandayam, ECE, Rowan University
%Divergence of a vector field

close all; clear;
x = -2:.2:2; y = -1:.2:1;    
[xx,yy] = meshgrid(x,y);     
s = xx.*exp(-xx.^2-yy.^2);
[px,py] = gradient(s,.2,.2);
figure(1);quiver(x,y,px,py,2);
xlabel('x');ylabel('y');
title('2-D vector field: {\bf P} = (1-2x^2)e^{-(x^2+y^2)} {\bf x} - 2xye^{-(x^2+y^2)} {\bf y}');

pause;

div_p=del2(s);
figure(2);surf(x,y,div_p);shading interp;rotate3d;
xlabel('x');ylabel('y');
title('Divergence of 2-D vector field: \nabla \cdot {\bf P}');

