"Euler method to solve first order differential equation for 1D SHM with boundary condition such that 
v[x=x0]=v0=0"

"f[t] plays the role of v(x) "
"G[t] plays the role of -(k/m)x "

(*initialisation*)
k=1.0;m=1.0;
f0=0;(*initial speed at x=x0*)
x0=1;(*max displacement*)
tinit=-x0;tfinal=x0;Nstep=1000;

(*define G[t]*)
G[i_]:=-(k/m)t[i];

(*end of 
initialisation*)

(*definitions*)
Deltat=(tfinal-tinit)/Nstep;
ilast=Nstep+1;
f[0]=f0;(*speed when x = x0*)
(*end of definitions*)

t[i_]:=tinit+i*Deltat;
For[i=0,i≤ilast-1,i++,
f[i+1]=f[i]+G[i]Deltat;
];
ttf=Table[{t[i],f[i]},{i,0,ilast-1}];
lptttf=ListPlot[ttf,PlotLabel->"f(t) vs. t",PlotRange->All];

ftheory[t_]:=f0+k*m*x0^2/2.0-k*t^2/(2m);
plt=Plot[ftheory[t],{t,tinit,tfinal},PlotRange->All,PlotStyle->Red];
Show[lptttf,plt]