% pcalg
clear all
dx=0.01; a=1;x=0:dx:a; n=length(x);EP=zeros(n,n);
D2=diag(ones([n-1,1]),-1)-2*diag(ones([n,1]),0)+diag(ones([n-1],1),1);D2=D2/dx^2;
H=-0.5*D2+EP;
[V,E]=eig(H);en=diag(E); norm=sqrt(trapz(x',V(:,1).^2)),psic=V(:,1)/norm; 
nq=1:n;,eex=nq.^2*pi^2/(2*a^2);psie=sqrt(2)*sin(pi*x); 
plot(x,psic),hold on,plot(x,psie,'k'),comp=[en(1:10) eex(1:10)'] 