# Numerically solving a particle in a box problem

A particle in box problem can be simplified to second order differential equation as:

$$-\frac{d^2}{dx^2}\psi(x)=E\psi(x)$$

with the boundary conditions: $$\psi(1)=\psi(0)=0$$

The goal is to find the energy $E$ (independent of x) and the wavefunction $\psi(x)$, where $0<x<1$.

The usual method is to guess an energy $E'$, then start from $x=0$ and advance a small step $dx$ until reach $x=1$. Check if $\psi(1)=0$. If it is , the guess is right, else re-guess.

My question is how to advance, since this is a second order differential equation, we need to know $\psi(0)$ and $\psi'(0)$ to advance. However, nothing about $\psi'(0)$ is provided.

My opinion is that we can not manually set $\psi'(0)=1$ or such, since this is explicitly assume that we are in ground states.

• Use finite differences. Look up the shooting method. – march Aug 20 '16 at 5:15

Different choices of $\psi'(0)$ will just scale up and down the whole wavefunction. Because it is easy to see that if you start with a certain $\psi'(0)$ to get a solution $\psi(x)$, an IC of $C\psi'(0)$ will just yield the solution $C\psi(x)$. The solution of the equation is determined only up to a multiplicative constant, which has to be determined by normalization of the wave function.

• You remind me, after that, we need to normalize. Thanks very much! – an offer can't refuse Aug 20 '16 at 5:23
• @buzhidao You are welcome! – velut luna Aug 20 '16 at 5:24

The usual method is to guess an energy $E′$, then start from $x=0$ and advance a small step $dx$ until reach $x=1$. Check if $ψ(1)=0$. If it is , the guess is right, else re-guess.

This simply isn't necessary. There's a simple and exact solution for this quantum system.

The SE for a particle in a 1D box with zero potential is:

$$-\frac{\hbar^2}{2m}\psi''(x)=E\psi(x)$$

Rework to:

$$\psi''+k^2\psi=0$$ Where: $$k^2=\frac{2mE}{\hbar^2}$$

This has an exact general solution:

$$\psi(x)=A\cos kx+B\sin kx$$

Boundary conditions:

$\psi(0)=0 \implies A\cos 0=0 \implies A=0$

So: $\psi(x)=B\sin kx$

and:

$\psi(1)=0\implies B\sin k=0$

Assuming $B \neq 0$, then: $$k=n\pi$$ With $n=1,2,3,...$ (the eigenvalues, i.e. quantum number).

$$k^2=\frac{2mE_n}{\hbar^2}=n^2\pi^2$$

That gives you the values for $E_n$ and $k_n$:

$$\psi_n(x)=B\sin k_nx=B\sin(n\pi x)$$

Determine $B$ by normalising:

$$1=\int_0^1\psi_n^2(x)dx$$

• yeah, I know this. I just want to solve it numerically. – an offer can't refuse Aug 20 '16 at 17:23
• @buzhidao There is still a simplification possible if you work numerically. If you just take some arbitrary guess for the energy and calculate the wavefunction numerically, you can rescale the coordinate: $\widetilde{\psi(x)} = \psi(\lambda x)$ where you choose $\lambda$ such that the zero of $\widetilde{\psi(x)}$ is at exactly $x = 1$. Under such a rescaling the energy transforms as $\widetilde{E} = \frac{E}{\lambda^2}$ and the potential transforms as $\widetilde{V} = \frac{V}{\lambda^2}$, but in this case $V = 0$ inside it is infinite outside so it remains invariant under scaling. – Count Iblis Aug 20 '16 at 17:32