% this function uses Euler's method to solve the IVP in 
%learning module 2.2
function R = Unlimited(tmax,N,k,R0)
%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
R = zeros(1,N+1); %define an empty population vector
R(1) = R0; %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
    R(n+1) = R(n) + (k*R(n))*dt;
end %end the for loop
t = linspace(0,tmax,N+1); %this is used only for the plotting
plot(t,R,'g*')
hold on
ylabel('R (Rabbits)'), xlabel('Time (months)'), title('Rabbits and more Rabbits')
tp = linspace(0,tmax,10*(N+1));
y = 2000*exp(k*tp);
plot(tp,y,'LineWidth',2)
plot(t,20000*ones(size(t)))
