%direction field logistic equation script

a = 2; %params for logistic
b = 1; %ditto
f = @(N) -(N.*(a-b*N));
N0 = 0.1;
NN0 = 5;
N_true = @(t) (a/b)./( 1 + ( (a-b*N0)/(b*N0) )*exp(-a*t)  );
NN_true = @(t) (a/b)./( 1 + ( (a-b*NN0)/(b*NN0) )*exp(-a*t)  );

h = 0.25;
[t,N]=meshgrid(-2:h:5,-2:h:5);
dN = f(N);
dt = ones(size(dN));
dNu = dN./sqrt(dt.^2+dN.^2);
dtu = dt./sqrt(dt.^2+dN.^2);
%dNu = dN; %non-normalized
%dtu = dt; %ditto

figure(5)
quiver(t,N,dtu,dNu,'m');
%hold on;
%plot(t(1,:),NN_true(t(1,:)),'k-',t(1,:),N_true(t(1,:)),'b-','LineWidth',1.25)
%hold off;
%legend('Direction Field','solution for N0>a/b','solution for N0<a/b')
axis([-2 5, -2 5])
xlabel('time: t')
ylabel('Population: N(t)')
title('Direction Field')
