%this function uses Euler's method to solve the logistic equation
function [y,t] = FermentEulers(tmax,N,Y0,A0)
%when calling this function, you need to pass the maximum time to run the
%simulation (tmax),
%the number of time steps (N), the parameters r and M, and the initial 
%population Y0.
dt = tmax/N; %this determines the size of the time step h
Y = zeros(1,N+1); %define an empty vector of yeast concentrations
A = zeros(1,N+1); %define an empty vector of alcohol concentrations
Y(1)=Y0;
A(1)=A0;
for n = 1:N %this is the iterative loop for Euler's Method
Y(n+1) = Y(n) + 0.2*Y(n)*(1-0.1*Y(n)-0.5*A(n))*dt; % Update the yeast
A(n+1) = A(n) + 0.05*Y(n)*dt; % Update the alcohol
end %end the for loop
t = linspace(0,tmax,N+1); %this is used only for the plotting
h1 = figure;%provide a handle for first figure (yeast)
h2 = figure;%provide a handle for second figure (alcohol)
%the code below is strictly used for plotting
figure(h1);
plot(t,Y)
ylabel('Yeast'), xlabel('Hours'), title('Euler''s Method Example')
figure(h2);
plot(t,A)
ylabel('Alcohol'), xlabel('Hours'), title('Euler''s Method Example')


