%this function uses Euler's method to solve the IVP y'=ry-h, y(0)=y0 that
%is discussed in learning module 2.2
function y = Eulers(tmax,N,r,h,y0)
%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).
%To run this m-file, you would enter something similar to (of course your 
%choice of parameters may be different)
%Eulers(10,100,.1,1.1,10);
%or if you would like to return the population vector y, enter
%y = Eulers(10,100,.1,1.1,10);
dt = tmax/N; %this determines the size of the time step h
y = zeros(1,N+1); %define an empty population vector
y(1) = y0; %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
    y(n+1) = y(n) + (r*y(n) - h)*dt;
end %end the for loop
t = linspace(0,tmax,N+1); %this is used only for the plotting
plot(t,y)
hold on
ylabel('Pounds of Seaweed'), xlabel('Time (Weeks)'), title('Euler''s Method Example')
