How can I generate the higher $n$ quantum harmonic oscillator wavefunction (in position space) numerically? Here, higher means around $n=500$, or say $n=2000$, where $n$ is the $n$th oscillator wavefunction.
The position-space wavefunction of the $n$th state involves Hermite polynomials of order n (see Griffith's book for the detailed form of the solution). I can generate wavefunction up to $n\approx 160$ only using 'gsl' library in C because the library doesn't offer Hermite polynomials of order higher than $\approx 170$.
To get rid of this limitation, I found that the higher $n$ wavefunctions can be achieved by using 'raising operator', and then repeatedly acting it on the previous wavefunction to get the next wavefunction, and so on.
Raising operator: $a^{\dagger} = \frac{1}{\sqrt{2}} \left(x - \frac{d}{dx}\right)$. (Consider, constants in the expression to be 1.)
In the expression, the derivative term, i.e., $d/dx$ needs to be evaluated. It can be solved either by the finite-difference method or by using Fourier transform to get 1st derivative (which is more accurate than the finite-difference method).
I wrote a Matlab program for $a^{\dagger}$ (shown below) using the 2nd method, i.e., Fourier transform. After evaluation of states greater than $n=10$, the program is becoming unstable and becoming even worse for higher $n$ (instability plot is shown below in the link). The same issue had appeared when I used the finite-difference method to evaluate the derivative (code is not attached).
Solution to the issue or an alternate approach to the problem will be helpful.
UPDATE: I'm also interested to know the reason for the development of instability while using 'fft' in the code.
sigma = 1.0;
xmin = -10.0;
xmax = 10.0;
npts = 512;
nstates = 14;
dx = (xmax-xmin)/npts;
x = xmin + dx*(0:npts-1);
% -- initial state/wavefunction
psi_init = exp(-0.5*x.^2/sigma^2)*(pi*sigma^2)^(-0.25);
psi = zeros(nstates,npts); % -- list to store oscillator states
psi(1,:) = psi_init;
for nn=2:nstates
psi(nn,:) = raising_psi(psi(nn-1,:),xmin,xmax,npts,sigma);
end
function adag_fn = raising_psi(previous_fn,a,b,n,sigma) % -- raising_operator
dx = (b-a)/n;
x = a + dx*(0:n-1);
% -- going into fourier space using 'fft' library
fwd_fft = fft(previous_fn);
k = (2*pi/(b-a))*[0:n/2-1,0,-n/2+1:-1];
dfk_dx = 1i*k.*fwd_fft; % -- 1st derivative in fourier space
df_dx = ifft(dfk_dx); % -- back into position space
% -- a^dagger acting on the previous state
adag_fn = (x.*previous_fn/sigma - sigma*real(df_dx))/sqrt(2);
norm_fn = adag_fn*transpose(adag_fn);
adag_fn = adag_fn/sqrt(norm_fn); % -- normalization
end