First-order (forward) Euler method for the QHO

stepsize

h=.01000000000000000000000000000000;

number of steps

n= 1000;

Guess for energy (in units of 1/2 hbar ω)

ϵ= 1.005687913746380211740000000000;

u=0.0000000000000000000000000000000;

Look for odd solutions

y1=0.000000000000000000000000000000;
y2=1.000000000000000000000000000000;

Look for even solutions

y1=1.0000000000000000000000000000000;
y2=0.0000000000000000000000000000000;

For[i=1,i<=n,i++,
u=u+h;
temp1=y1;
temp2=y2;
y1=temp1+h*temp2;
y2=temp2 + h*(u^2-ϵ)*temp1;
a[i]=u; b[i]=y1;
]

ListPlot[Table[{a[i],b[i]},{i,1,n}],PlotRange->{-5,5}]

ListPlot[Table[{a[i],b[i]},{i,1,n}],PlotRange->{-0.1,1.1}]