The question:

Write a Matlab M-file that uses Euler’s method to numerically solve the IVP: dy/dt = y, y(1859) = 12. Solve the IVP up to the year 1864 using a step size of 0.1 years. This is modelling the exponential growth of rabbits in Australia for five years from the introduction of 12 rabbits at the start of 1859.

We are then given this code as an example:

t=0:0.5:5;

y(1)=1;

for i = 1:10

y(i+1)=y(i)+t(i)^2*0.5;

end

plot(t,y,’b:’)

hold on

yexact = t.^3/3+1;

plot(t,yexact,’r--’)

legend(’Numerical solution’, ’Analytical solution’);

title(’Example IVP solution’)

xlabel(’t’)

ylabel(’y’)

I used that code and then modified in in a way which I thought would give me what I need, for the first part anyway (without the labelling etc.):

clear all

t=1859:0.1:1864;

y(1)=12;

for i = 1:50

y(i+1)=y(i)+y(i)*0.1;

end

y(50)

plot(t,y,'-')

However this isn't giving me what I need.

Any suggestions would be greatly appreciated.