Solutions

Logistic Growth

You should have created a function file that looks something like this:

In [12]:
function [rhs_value] = log_growth(N,r,K)
%%Evaluates the RHS of the logistic growth equation for given values of N,r, and K.
%INPUTS:
% N : Vector of population values
% r : Scalar, growth rate
% K : Scalar, population capacity
%OUTPUTS:
% rhs_value : Vector of the same shape as N. Value of the RHS given the inputs.
rhs_value = r*N .* (1 - N./K);
end %function

And then your script should look something like this, giving an output like the one shown below.

In [13]:
%the initial conditions and parameters of the equation
tRange = [0, 30];
init = 20;
r = 0.15;
K = 50;
%the function handle that we need - notice the dummy variable t
fun = @(t,N) log_growth(N,r,K);
[tVals, NVals] = ode45(fun, tRange, init);
figure;
plot(tVals, NVals, '-b');
xlabel('Time, $t$','interpreter','latex');
ylabel('Duck population, $N$','interpreter','latex')
title('Logistic growth solution','interpreter','latex')

Of course, now that you have a method of modelling the population, and a script which lets you change the values of the parameters, you can investigate what would happen if the growth rate was greater or smaller, if the lake was expanded to make room for more ducks, or if the population started out smaller or larger than the maximum capacity.