%this function uses Euler's method to solve the IVP in learning module 2.2
function p = Logistics(tmax,N,r,K,p0)
%when calling this function, you need to pass the maximum time (tmax),
%the number of time steps (N), the parameters r and h, and the initial 
%population (y0).
dt = tmax/N; %this determines the size of the time step h
p = zeros(1,N+1); %define an empty population vector
p(1) = p0; %set the first value in the population vector to the inital pop.
for n = 1:N %this is the iterative loop for Euler's Method
    p(n+1) = p(n) + r*p(n)*(1 - p(n)/K)*dt;
end %end the for loop
t = linspace(0,tmax,N+1); %this is used only for the plotting
plot(t,p)
hold on
ylabel('Population'), xlabel('Time'), title('Euler''s Method Example')
