n=10;%number of steps test=@(t,x) -t*x;%right-hand side of the d.e. we are using for testing purposes t=linspace(0,4,n);%parameter x=exp(-t.^2/2);%exact solution to our equation [xe,t]=euler(test,1,0,4,n);%euler method [x2,t]=rk2(test,1,0,4,n);%Runge-Kutte 2. order figure(1); clf hold on plot(t,x,'b;exact solution;'); plot(t,xe,'r;euler method;'); plot(t,x2,'g;rk2 method;');