%
%  code3Wa.m -- 18 sept 02 -- djm
%  (from code3Ma.m -- 16 sept 02)
%

%  clear workspace & graphics

clear;  close all

%  set t & v grid matrices ("help meshgrid")

ds = 0.2;  x = -3-ds/2:ds:3+ds/2;  y = -3-ds/2:ds:3+ds/2;
[xx,yy] = meshgrid(x,y);

%  calculate tangent vectors (dt,dv)

dx = ones(size(xx));  dy = (xx - exp(-xx))./(yy + exp(yy));
ds = sqrt(dx.^2 + dy.^2);

%  plot tangent vectors ("help quiver") 

figure(1);  hold on
quiver(xx,yy, dx./ds, dy./ds,0.3,'k')
quiver(xx,yy,-dx./ds,-dy./ds,0.3,'k.')
plot(xx(:),yy(:),'r.')
axis([-3 3 -3 3]);

%  label plot

title(['\bf integral curve & tangent field (#2.2.7) - vectors scaled to equal length'])
xlabel('x-axis')
ylabel('y-axis')

%  contourplot

f = 0.5*(yy.^2 - xx.^2) + exp(yy) - exp(-xx);
K = -0.5+exp(1);

contour(x,y,f,[K K],'b')
plot(0,1,'bo')