%Question 2 - An algorithmic implementation of the Euler Method clc; close all; %Part 1a k = (2/3); h = 0.01; %time step myeuler(1) = 10; timesteps1 = 85/h; for t = [2:1:timesteps1+1] myeuler(t) = myeuler(t-1) - h*k*myeuler(t-1); end timevect1 = [0:h:85]; figure; plot(timevect1,myeuler) title('Figure 5: h = 0.01 implementation of the Euler algorithm') anasoln1 = myeuler(1)*exp(-(2/3)*timevect1); mse21a = mse(anasoln1 - myeuler) %Part 1b k = (2/3); h2 = 0.001; %time step myeuler1(1) = 10; timesteps2 = 85/h2; for t = [2:1:timesteps2+1] myeuler1(t) = myeuler1(t-1) - h2*k*myeuler1(t-1); end timevect2 = [0 : h2 : 85]; figure; plot(timevect2,myeuler1) title('Figure 6: h = 0.001 implementation of the Euler algorithm') anasoln2 = myeuler1(1)*exp(-(2/3)*timevect2); mse21b = mse(anasoln2 - myeuler1) %The error for the Runge-Kutta Method is in the order of 10^(-11) while the %error for the Euler method in part b is in the order of 10^(-8), showing %that the Runge-Kutta method is more accurate, but the Euler method is good %for first approximations.