% ohalg
clear all
dx=0.01; L=5;x=-L:dx:L; n=length(x);
%D2=toeplitz([-2 1 zeros(1,n-2)])/dx^2;
D2=diag(ones([n-1,1]),-1)-2*diag(ones([n,1]),0)+diag(ones([n-1],1),1);D2=D2/dx^2;
hbar=1;m=1;k=1;pot=0.5*k*x.^2;H=(-hbar^2/(2*m))*D2+diag(pot);
[V,E]=eig(H);en=diag(E);
norm=sqrt(trapz(x',V(:,10).^2)),psic=V(:,10)/norm;plot(x,psic.^2)
nq=0:n;exa=(nq+0.5);[en(1:5) exa(1:5)']