%direction field for general DE dy/dx = f(x,y)
%f(x,y) defined below

f = @(x,y) x + y; %function handle to RHS of logistic equation

Y = @(x) -x -1 + exp(x+2);

h = 0.25;
[x,y] = meshgrid(-2:h:6,-2:h:6); % 2-dimensional partition of values
dy = f(x,y);
dx = ones(size(dy));
dyu = dy./sqrt(dx.^2+dy.^2); % normalize 
dxu = dx./sqrt(dx.^2+dy.^2); % normalize
%dyu = dy; %non-normalized
%dxu = dx; %ditto

figure(1)
quiver(x,y,dxu,dyu,'m'); hold on;
plot([-2:h:6],Y([-2:h:6]),'b-'); hold off;

axis([-2 6, -2 6])
xlabel('x')
ylabel('y(x)')
title('Stunning Direction Field!')


