clear all
%timestep
dt = 0.2;
%final time
T = 5;
%no of steps
tsteps = ceil(T/dt);
% initial condition
x0 = 2;

time =0;
xn = x0;

% save the discrete time and solution values
tdata = time;
xdata = x0;

%the Euler method
for n=1:tsteps,
    fn = rhseuler(time,xn);
    xn = xn + dt*fn;
    time = dt*n;

	% save data
	tdata = [tdata time];
	xdata = [xdata xn];
end;	

plot(tdata,xdata); hold on;
plot(tdata,xdata,'ko')
xlabel(['\bf t'],'fontsize',12)
ylabel(['\bf x(t)'],'fontsize',12)
    
% the vector tdata contains the set of discrete times t0,t1,...,tn,...,T
% the vector xdata contains the approximations x0,x1,...,xn,...
% ploting xdata versus tdata means plotting the "numerical" solution
% x(end) represents the last element of this vector, it is the numerical
% solution at time =T.