%% Example for curl and div of a 2D vector field

%% You need to download new m-files.
% Download the files <../vectorfield.m vectorfield.m>, <../ezpcolor.m ezpcolor.m>, <../colorposneg.m colorposneg.m>


%% (1) Plot a 2D vector field
% Plot the 2D vector field F = ( cos(x+2*y), sin(x-2*y) ) for x,y in [-2,2].

syms x y z real
F = [ cos(x+2*y), sin(x-2*y) ];
vectorfield(F,-2:.25:2,-2:.25:2)

%% (2) Find G = curl(F) and plot G_3 together with vector field

G = curl([F,0],[x y z])                % need vector field of 3 components for curl

vectorfield(F,-2:.25:2,-2:.25:2); hold on
ezpcolor(G(3),[-2.5 2.5 -2.5 2.5]); hold off 
colorbar; colorposneg
title('colors show curl: blue is clockwise, red is counterclockwise')

%% (3) Find div(F) and plot it together with vector field

g = divergence(F,[x y])                % find divergence

vectorfield(F,-2:.25:2,-2:.25:2); hold on
ezpcolor(g,[-2.5 2.5 -2.5 2.5]); hold off 
colorbar; colorposneg
title('colors show divergence: blue is sink, red is source')

