Sample code 10.4: A more robust code to evaluate the EigenStates (eigenEnergies, Eigen wavefuntion) of a generic potential V(x) for the 1-D TISE.

SetDirectory["C:\\Users\\Yoon\\Documents\\teaching\\ZCE111\\1011SEM2\\notes\\lecture10\\TISE"];
(*SetDirectory["C:\\Users\\Yoon\\Documents\\presentation\\NQM\\TISE"];*)

<<potential.m;(*choose the potential in potential.m*)

(*<<potential_extra.m;(*choose the potential in potential.m*)*)

eigenEnergy[1]=Eini;(*En=Eini;*)

For[n=1,n≤nlast,n++,
If[n≠1,En=eigenEnergy[n-1]+k*Abs[eigenEnergy[n-1]],
En=eigenEnergy[n]];(*end if*)
Print["{n, Initial En} ",n ," ",En];
(*****************)
<<Matching.m;
txphiL=Table[{N[i*Deltax],phiL[i]},{i,iini,ilast}];
txphiR=Table[{N[i*Deltax],phiR[i]},{i,iini,ilast}];
txV=Table[{i*Deltax,N[V[i]]},{i,iini,ilast}];
Print[
ListPlot[{txphiL,txphiR,txV},PlotLabel->"phi, V vs x, Normlaised.",
Joined->True,
PlotStyle->{PointSize[0.0015]},PlotRange->{{xini,xlast},{-5,10}}]];
Print[" "];
(*****************)
eigenEnergy[n]=En;
(*Egap=eigenEnergy[n]-eigenEnergy[n-1];*)
];(*end for n*)
tneigenEnergy=Table[{n,eigenEnergy[n]},{n,1,nlast}]
ListPlot[tneigenEnergy]