f=inline('2*t*y','t','y'); % right-hand side y'=f(t,y) sol=inline('exp(t^2)','t'); % exact solution x(0)=1 h=0.2; %step size [teuler,yeuler]=eul(f,[0,2],1,h) [trk2,yrk2]=rk2(f,[0,2],1,h) [trk4,yrk4]=rk4(f,[0,2],1,h) ezplot(sol,[0,2]) hold on plot(teuler,yeuler,'o') %plotting Euler approx plot(trk2,yrk2,'*') %plotting rk2 approx plot(trk4,yrk4,'+') %plotting rk4 approx legend('Exact', 'Euler', 'RK2', 'RK4') title('Exact solution vs. numerical methods') axis([0 2.1 0 56]) hold off