For a particle in an infinite square well of length $L$ centered at the origin (see Figure 2), the potential $V(x)$ is given by
\[ V(x) =\begin{cases}0,\textrm{ if } -L/2 \leq x \leq L/2 \tag{1} \label{Eq:V=0}\\\infty, \textrm{ otherwise.}\end{cases} \]
Since the particle cannot be found outside the well, the wave function $\Psi(x)$ outside the well is set to zero with
\[ \Psi(x) = 0 \text { when } x<-L/2 \text{ or } x>L/2 \]
In order to have $\Psi(x)$ remain continuous, the Dirichlet boundary conditions are set as
\[ \Psi(-L/2)=\Psi(L/2) = 0 \tag{2} \label{Eq:Boundary} \]
As with the asymmetric well (see Asymmetric Well), no requirement for continuity is made on $d \Psi(x)/dx $ at the boundary.
In the majority of introductory textbooks, the general solution to the Time-Independent Schrodinger equation for the potential described by Eq.\eqref{Eq:V=0} is given as
\[ \Psi(x) = A \cos kx + B \sin kx \qquad A,B \in \mathbb{R} \tag{3}\label{Eq:CosSinSolutions} \]
with
\[ k = \sqrt{\frac{2mE}{\hbar^2}} \tag{4} \label{Eq:k1} \]
Applying the boundary conditions Eq.\eqref{Eq:Boundary} to Eq.\eqref{Eq:CosSinSolutions} results in
\[ A \cos k \Big (\frac{L}{2} \Big ) + B \sin k \Big( \frac{L}{2} \Big ) = 0 \tag{5} \label{Eq:CosSinZero} \]
Satisfying the requirements for Eq.\eqref{Eq:CosSinZero} results in two unique solutions given by
\[ \Psi_{n=\textrm{odd}}(x) = (2/L)^{1/2} \cos \Big ( \frac{n \pi}{L} x \Big ) \qquad n=1,3,5, \dots \label{Eq:Psi1} \]
and
\[ \Psi_{n=\textrm{even}}(x) = (2/L)^{1/2} \sin \Big ( \frac{n \pi}{L} x \Big ) \qquad n=2,4,6, \dots \label{Eq:Psi2} \]
with
\[ k_{n} = \frac{n \pi}{L} \tag{6} \label{Eq:k} \]
From Eq.\eqref{Eq:k1} and Eq.\eqref{Eq:k}, the energy $E$ is quantized as
\[ E_{n} =\frac{n^{2} \pi ^{2} \hbar^{2}}{2mL^{2}}\qquad n=1,2,3, \dots \label{Eq:E1} \]