 clear; clf; 
 dt=0.2; tend=5;
//// Euler method
 x=1; xEuler=x;
 for t=dt:dt:tend
     x=x+dt*(1-x+t); xEuler=[xEuler,x];
 end
//// Second order
 x=1; xSecond=x;
 for t=dt:dt:tend
     x=x+dt*(1-x+t)+dt^2*(1-x)/2; xSecond=[xSecond,x];
 end
//// SciLab solver

function y=ode_function(x,t) 
  y=1-x+t;
endfunction
  
 t=(0:0.1:tend)'; 
 xSL=ode(1,0,t,ode_function);
//// Plotting results
 x=t+exp(-t); plot(t,(xSL'-x)./x,'r');
 t=0:dt:tend; x=t+exp(-t);
 plot(t,(xEuler-x)./x);
 plot(t,(xSecond-x)./x,'g');
//// Plot dt error
figure; xDIFF=[];
 for dt=0.01:0.01:1
     x=1; for t=dt:dt:2; x=x+dt*(1-x+t); end
     xDIFF=[xDIFF,(x-2-exp(-2))/(2+exp(-2))];
 end
 dt=0.01:0.01:1;  plot(dt,xDIFF);
