% Calculate eigenfunctions of the Harmonic oscillator.

function eigf=eigenfun(i,x,alpha)
expo=exp(-0.5*alpha.*x.*x);
c=alpha^0.5;
q=c.*x;
norm=pi^0.5*2^(i-1)/c;

% multiply by factorial.

for j=1:(i-1);
norm=norm*j;
end;
norm=norm^(-0.5);

hermite(1,:)=1.*ones(1,length(q));
hermite(2,:)=2.*q;
hermite(3,:)=4.*q.*q-2.*ones(1,length(q));
for n=4:i;
hermite(n,:)=2.*q.*hermite(n-1,:)-2*(n-2).*hermite(n-2,:);
end;

eigf=norm.*hermite(i,:).*expo;

end;


