%% Modeling Yeast Growth
%% Kurt Bryan and SIMIODE
%
% Notebook to support Exercise 3.4.8, modeling yeast population growth.
% The data, in time/population pairs.

times = [0:17];
pop = [9.6, 18.3, 29, 47.2, 71.1, 119.1, 174.6, 257.3, 350.7, 441, 513.3, 559.7, 594.8, 629.4, 640.8, 651.1, 655.9, 659.6];

% A plot:

plt1 = plot(times,pop,'-r');

% Given that u(0) = 9.6, the solution to the logistic equation with intrinsic growth rate "r" and carrying capacity "K" is

u = @(t,r,K) K./(1+exp(-r*t)*(K/9.6-1))

% A least-squares function can be formed as

syms SS(K,r)
SS(K,r) = sum((u(times,K,r)-pop).^2);

% Now adjust r and K to minimize this.