%
%  w02div.m -- flows & divergence (djm, 12 jan 2004)
%
%  flow arrows

clear;  close all

L = pi;  ds = 2*L/13;

%  set x & y-vectors &  grid matrices ("help meshgrid")

x = -L:ds:+L;  y = -L:ds:+L;
[xx,yy] = meshgrid(x,y);
rr = sqrt(xx.^2 + yy.^2);

%- - - - - 

%  calculate velocity

uu = cos(xx).*sin(yy);  vv = sin(xx).*cos(yy);

%  plot vector field ("help quiver") outside unit circle ("help gt")

figure(1)
quiver(x,y, uu, vv,0.5)
hold on
quiver(x,y,-uu,-vv,0.5,'.')
axis([-L +L -L +L]);  axis square;

%  label plot

title(['\bf flow vectors (u=cos(x)*sin(y), v=sin(x)*cos(y))'])
xlabel('\bf x-axis')
ylabel('\bf y-axis')

%  contour of divergence:  div = u_x + v_y on finer grid

x = -L:ds/20:+L;  y = -L:ds/20:+L;
[xx,yy] = meshgrid(x,y);
div = -2*sin(xx).*sin(yy);

contour(x,y,div,[0:0.4:2],'k')
contour(x,y,div,[-2:0.4:0],'k--')
contour(x,y,div,[0 0],'r')

