>> %%MATLAB 3 MAT275
>> %Exercise 1
>> %Part a
>> f=inline('2*y','t','y');
>> t=linspace(0,.5,100); y=3*exp(2*t); %defines the exact solution of the ODE
>> [t5,y5]=euler(f,[0,.5],3,5); %solves the ODE using Euler with 5 steps
>>approx=y5(end)
approx =
7.4650
>> exact=y(end)
exact =
8.1548
>> e5=abs(approx-exact)
e5 =
0.6899
>> [t50,y50]=euler(f,[0,.5],3,50); %solves the ODE using Euler with 50 steps
>> approx=y50(end)
approx =
8.0748
>> exact=y(end)
exact =
8.1548
>> e50=abs(approx-exact)
e50 =
0.0801
>> ratio=e5/e50
ratio =
8.6148
>> [t500,y500]=euler(f,[0,.5],3,500); %solves the ODE using Euler with 500 steps
approx =
8.1467