%% logistic equation
clear all
close all
clc

f=@(x)(x.*(1-x))

N=linspace(-0.5,1.5,100);
figure(1)
hold on
plot(N,f(N),'r-','Linewidth',2)
plot(0,0,'sk','MarkerSize',8)
quiver(0,0,-0.2,-0.2,...
    0, 'MaxHeadSize',1,'color',[0 0 1])
quiver(0,0,0.2,0.2,...
    0, 'MaxHeadSize',1,'color',[0 0 1])
quiver(1+0.2,0-0.2,-0.2,+0.2,...
    0, 'MaxHeadSize',1,'color',[0 0 1])
quiver(1-0.2,0.2,0.2,-0.2,...
    0, 'MaxHeadSize',1,'color',[0 0 1])
legend('f(N)=N(1-N)','critical points','stability','Location','South')
plot(1,0,'sk','MarkerSize',8)
plot(N,0*ones(100,1),'k-')
ylabel('N(1-N)','fontsize',16)
xlabel('N','fontsize',16)
title('Phase lines of the logistic equation','FontSize',16)
hold off

print -f -depsc 'Logistic1.eps'

%%
clear all
close all
clc

Nex=@(t,N0)( N0./(N0+(1-N0)*exp(-t)) );

t=linspace(0,4,100);

hold on
plot(t,Nex(t,-0.01),'r-','Linewidth',2)
plot(t,Nex(t,0.4),'b-','Linewidth',2)
plot(t,Nex(t,1.5),'g-','Linewidth',2)
legend('N_0=-0.01','N_0=0.4','N_0=1.5','Location','SouthWest')
plot(t,1*ones(100,1),'k--')
xlabel('t','FontSize',20)
ylabel('N(t)','FontSize',20)
title('Solutions of the logistic equation')
hold off

print -f -depsc 'Logistic2.eps'
