Solution (source code)

= Solution

Inside the <infinite square well>, the <Schrödinger equation> and <Dirichlet boundary conditions> are
$$
i\hbar\frac{\partial\Psi}{\partial t}=-\frac{\hbar^2}{2m}\frac{\partial^2\Psi}{\partial x^2},\qquad 0<x<a,\qquad \Psi(0,t)=\Psi(a,t)=0.
$$
The <wavefunction> vanishes outside the box. These walls constrain its values, not its first derivatives: requiring both to vanish at an endpoint would eliminate all the nonzero stationary solutions.

For a nonzero separated solution, <separation of variables> gives
$$
i\hbar\frac{T'}T=-\frac{\hbar^2}{2m}\frac{\psi''}\psi=E,\qquad T(t)=T(0)e^{-iEt/\hbar},\qquad -\frac{\hbar^2}{2m}\psi''=E\psi.
$$
The last equation is the <time-independent Schrödinger equation>. Its <energy eigenvalue> is real. Multiplication by $\psi^*$ and <integration by parts>, with the endpoint values zero, gives
$$
E\int_0^a|\psi|^2\,dx=\frac{\hbar^2}{2m}\int_0^a|\psi'|^2\,dx\geq0.
$$
Equality would force $\psi$ to be constant and hence zero, so a nonzero <energy eigenstate> has $E>0$. Writing $k=\sqrt{2mE}/\hbar$, the general solution is $A\sin kx+B\cos kx$. The left wall gives $B=0$; the right gives $\sin ka=0$. Negative integers reproduce the same functions up to a constant, and $n=0$ gives the zero function, leaving $k=n\pi/a$ for $n=1,2,\ldots$.

Finally $\int_0^a\sin^2(n\pi x/a)\,dx=a/2$. Thus <wavefunction normalization> with positive coefficient gives
$$
\boxed{\psi_n(x)=\sqrt{\frac2a}\sin\frac{n\pi x}{a},\qquad E_n=\frac{n^2\pi^2\hbar^2}{2ma^2},\qquad n\geq1.}
$$
An arbitrary constant <global phase> has no effect on the <quantum state>.