% This is the main function to solve the logistic growth % dN/dt = r(1-N/K)N in p.212, Mathematical Models in Biology global r K K = 10; % carrying capacity r = 1; % reproduction rate options = odeset('RelTol',1e-4,'AbsTol',1e-4); t0 = 0; tfinal = 3; for N_ini = 0:2.5:20; [T,N] = ode45(@logisticgrowth,[t0 tfinal],N_ini,options); % plot N at different T figure(1); hold on; plot(T,N) xlabel t, ylabel N % plot exact solution Nexact = N_ini*K./(N_ini+(K-N_ini)*exp(-r*T)); figure(2); hold on plot(T,Nexact,'r') xlabel t, ylabel('exact solution of N') pause(3) end