% integrates the simple model from Eq. (1) in Problem Set 2
% we use ode45, which is a Runge-Kutta method (basically a fancy Euler method)
% for Matlab reasons the ODE function itself needs to be defined at the end of the script

% DEFINE PARAMETERS: this is what you might need to change
% constants r, a, and b
r = 1;
a = 8;
b = 13;

% set up start and end times of the integration
tstart = 0;
tend = 1;

% timestep 
dt = 0.01;

% initial condition 
N0 = 4; 

% INTEGRATE AND PLOT
t = linspace(tstart,tend,floor((tend-tstart)/dt));

[t_out,N] = ode45(@(t,N) odefcn(t,N,r,a,b),t,N0);

plot(t_out,N)

% DEFINE ODE FUNCTION
function ndot = odefcn(t,N,r,a,b)
    ndot = r*N*(-N^2+a*N-b);
end

