%define the function file
function [vdot] = growth(t,v)     % a general growth model where the cocentration of nutrient does not have any influence on the bacterial growth

%Declare parameters 
k=0.8;            % Rate constant
cmax = 3;     % Maximum nutrient concentration
n =6;        % the Hill coefficient, describes how cooperative the two variable are
Ka = 2.7;      % half the initial nutrient concentration

%Declare time points
t0=1.5;
t1=2;
t2=3;
t3=12;

ft=zeros(size(t)); %Nutrient concentration

%Generate nutrient conc against time
for i=1:length(ft)
    if t(i) < t0
        ft(i) = 0;          % where ft stands for f(t)
    else
        if t(i)>= t0 && t(i)<t1
        ft(i) = (cmax / (t1-t0))*(t(i)-t0);
        else
            if t(i)>=t1 && t(i) <= t2
                ft(i) = cmax;
            else
                if t(i)> t2 && t(i) <= t3
                    ft(i) = cmax+(cmax / (t2-t3))*(t(i)-t2);
                else
                    if t(i)> t3
                        ft(i) = 0;
                       
                end;
            end;
        end;
    end;
end;
end;

vdot = (k*((ft).^n) ./ ( ((Ka)^n) + (ft).^n))*v;    %the ODE



%calling the function
[t, v] = ode45('growth', [0,15], 0.4);  %an ODE solver

figure;
axis([0 15 0 10]);
plot(t, v, 'o-'), xlabel('time(s)');
ylabel('growth of bacteria in volume');
title('Growth of bacteria in volume when the internal concentration is a given function f(t)');


