% This program solves the differential equation that models spruce budworm population. The model has the form
% du/dt = f(t,u) = ru(1-u/q) + u^2/(1 + u^2)
function budworm % Define a function called budworm, note that this function has the same name as
% the .m file.
tspan = [0; 100]; %This command defines the time interval of interest.
u0 = [.1]; %This command tells MATLAB the initial condition.
[t,u] = ode15s(@f,tspan,u0); % This command tells MATLAB to use the differential equation solver called ode15s to
% numerically compute the solution of the differential equation defined by the
% function f, for time interval tspan, and initial condition u0. The right-hand
% side of the equation tells MATLAB to store this output in vectors t (for the
% time points) and u (for the population density).
figure;
plot(t,u(:,1)); %This tells MATLAB to plot the solution.
% --------------------------------------------------------------------------
function dudt = f(t,u) %This commands defines the function du/dt = f(t,u).
r = .1; %Now define the parameters.
q = 10;
dudt = [r*u(1)*(1-u(1)/q) - u(1)^2/(1+u(1)^2)]; %This command inputs the left-hand side of the spruce budworm
%differential equaion.