Method of separation of variables for heat equation I'm trying to solve the following problem of the heat equation using the method of variables separation
\begin{equation}
\begin{aligned}
\partial_t u = \alpha^2 \partial_x^2u, t>0, x\in(0,l) \\
u(t,0) = 0 = u(t,l), t \geq 0, \\
u(0,x) = \phi(x), x \in E[0,l]
\end{aligned}
\end{equation}
I know how to prove that $X(0)=X(l) = 0$ so I don't get trivial solutions and find the solutions for $X(x)$ and $T(t)$
\begin{equation}
X(x) = A\cos(\sqrt{\lambda} x) + B \sin(\sqrt{\lambda}x)
\end{equation}
\begin{equation}
T(t) = C\exp(-\lambda \alpha^2t)
\end{equation}
But I'm having troubles showing that:
\begin{equation}
u_n(t,x) = \sin \frac{(2n - 1)\pi x}{2l}\exp \left( - \frac{(2n-1)^2 \pi^2 \alpha^2}{4l^2}t\right), n \in Z^+
\end{equation}
and
\begin{equation}
u(t,x) = \sum_{n=1}^\infty c_n u_n(t,x)
\end{equation}
By superposition and using the fact that $\lambda = \left(\frac{n \pi}{l}\right)^2$
\begin{equation}
u(t,x) = \sum_{n=0}^\infty b_n\sin \left(\frac{n \pi x}{l}\right) \exp\left(\frac{n^2\pi^2 \alpha^2t}{l^2} \right)
\end{equation}
My attempt
I have
\begin{align}
\phi(x) = u(0,x) = \sum_{n=1}^\infty b_n \sin \left(\frac{n \pi x}{l}\right) \\
\end{align}
and
\begin{align}
(\phi|X_m) = \frac{l}{2}b_m \\
b_k = \frac{2}{l}\int_0^l \phi(x)\sin \frac{n \pi x}{l} dx = 2u_0 \int_0^l \sin \frac{n \pi x}{l} dx
\end{align}
So the integral can be solved for $b_n$ as follows
\begin{equation}
\begin{aligned}
b_n =  2u_0 \int_0^l \sin \frac{n \pi x}{l} dx = 2u_0 \frac{l \cos(\frac{n \pi x}{l})}{\pi n}|_0^l = 2u_0 \frac{l - l\cos(\pi n)}{\pi n} \\
= 2u_0 l \frac{1-\cos(\pi n)}{\pi n}  = -\frac{2 u_0 l}{\pi n} ((-1)^n - 1)\\
= \left \{ 
\begin{matrix}
0 \text{ when n is even} \\
\frac{4u_0 l}{n\pi} \text{ when n is odd}
\end{matrix}
\right .
\end{aligned}
\end{equation}
But I cant figure out from here how to get to $u_n(t,x)$ and $u(t,x) = \sum_{n=1}^\infty c_nu_n(t,x)$
 A: You want to follow the standard prescription by assuming a separated solutions of the form $X(x)T(x)$ and then separate variables to obtain
$$
          \frac{1}{\alpha^2}\frac{T'(t)}{T(t)}=\lambda = \frac{X''(x)}{X(x)},\;\;\;
              X(0)=X(l)=0.
$$
where $\lambda$ is a separation constant. The $X$ equation determines the parameters $\lambda$:
$$
             X''(x)-\lambda X(x)=0,\;\;\; X(0)=X(l)=0.
$$
There are no solutions if $\lambda > 0$ because you end up with $\sinh$ or $\cosh$, and these functions do not have two real zeroes. The solutions are $\lambda = -n^2\pi^2/l^2$, leading to solutions $X_n(x)=\sin(n\pi x/l)$ for $n=1,2,3,\cdots$. The equations in $T$ must satisfy
$$
             T'(t)=-\frac{\alpha^2 n^2\pi^2}{l^2}T(t).
$$
So the $T$ solutions are
$$
                T(t) = \exp\left\{-\frac{\alpha^2n^2\pi^2}{l^2}t\right\}
$$
The general separated solution is
$$
        u(t,x) = \sum_{n=1}^{\infty}C_n \exp\left\{-\frac{\alpha^2 n^2\pi^2}{l^2}t\right\}\sin(n\pi x/l)
$$
The constants are determined by Fourier Series techniques and the initial condition
$$
          \phi(x) = u(0,x) = \sum_{n=1}^{\infty}C_n\sin(n\pi x/l)
$$
The coefficients are determined by orthogonality conditions:
$$
          \int_0^l \phi(x)\sin(n\pi x/l)dx=C_n\int_0^l\sin^2(n\pi x/l)dx \\
       C_n = \frac{\int_0^l \phi(x)\sin(n\pi x/l)dx}{\int_0^l\sin^2(n\pi x/l)dx}.
$$
