Until now, we have been working only with the heat equation. Today, we are going to solve the one-dimensional wave equation with homogeneous boundary conditions and no sources, namely,
$$\begin{align}
u_{tt}&=c^2u_{xx},\\
u(0,t)&=0,\quad u(L,t)=0,\\
u(x,0)&=f(x),\quad u_t(x,0)=g(x).
\end{align}$$
As before, we want to use the method of separation of variables by setting $u(x,t)=\phi(x)h(t)$ and substituting above:
$$
\phi h''=c^2\phi''h.
$$
We want to ignore trivial solutions. This implies our boundary conditions are $\phi(0)=0$, and $\phi(L)=0$.
Separating variables yields
$$
\frac{\phi''}{\phi}=\frac{h''}{c^2h}\color{blue}{=-\lambda},
$$
Because functions of distinct independent variables can only be equal if they equate to the same constant, we have introduced the equality in blue (the negative sign is purely out of convenience later on).
We now have a system of two ordinary differential equations:
$$\begin{align}
\phi''&=-\lambda\phi,\tag{1}\\
h''&=-\lambda c^2h.\tag{2}
\end{align}$$
Equation $(1)$ has three cases:
- $\lambda<0$:
$$
\phi(x)=c_1\sinh\sqrt{-\lambda}x+c_2\cosh\sqrt{-\lambda}x.
$$
Applying the boundary conditions to this yields
$$\begin{align}
\phi(0)&=c_2=0,\\
\phi(L)&=c_1\sinh\sqrt{-\lambda}L=0\Longrightarrow c_1=0.
\end{align}$$
This is the trivial solution, so we drop it.
- $\lambda=0$:
$$
\phi(x)=c_1x+c_2.
$$
Applying the boundary conditions to this yields
$$\begin{align}
\phi(0)&=c_2=0,\\
\phi(L)&=c_1L=0\Longrightarrow c_1=0.
\end{align}$$
This is the trivial solution, so we drop it.
- $\lambda>0$:
$$
\phi(x)=c_1\sin\sqrt{\lambda}x+c_2\cos\sqrt{\lambda}x.
$$
Applying the boundary conditions to this yields
$$\begin{align}
\phi(0)&=c_2=0,\\
\phi(L)&=c_1\sin\sqrt{\lambda}L=0\\
&\Longrightarrow\lambda_n=\left(\frac{n\pi}{L}\right)^2,\\
\phi_n(x)&=C_n\sin\frac{n\pi x}{L}.
\end{align}$$
Now that we know the value of $\lambda_n$, we can use it to solve equation $(2)$:
$$
h_n(t)=A_n\sin \frac{n\pi ct}{L}+B_n\cos \frac{n\pi ct}{L}.
$$
Therefore, by the
principle of superposition, we find that the solution to this partial differential equation is
$$
\color{blue}{u(x,t)=\sum_{n=1}^{\infty}\left(G_n\sin \frac{n\pi ct}{L}+F_n\cos \frac{n\pi ct}{L}\right)\sin\frac{n\pi x}{L}.}
$$
The coefficients $F_n$ and $G_n$ can be found by applying the initial conditions:
$$
u(x,0)=\sum_{n=1}^{\infty}F_n\sin\frac{n\pi x}{L}=f(x).
$$
$$\begin{align}
u_t(x,t)&=\sum_{n=1}^{\infty}\frac{n\pi c}{L}\left(G_n\cos \frac{n\pi ct}{L}-F_n\sin \frac{n\pi ct}{L}\right)\sin\frac{n\pi x}{L},\\
u_t(x,0)&=\sum_{n=1}^{\infty}G_n\frac{n\pi c}{L}\sin\frac{n\pi x}{L}=g(x).
\end{align}$$
Finally, applying
orthogonality principles to the above equations to find $F_n$ and $G_n$ yields
$$\begin{align}
\color{blue}{F_n}&\color{blue}{=\frac{2}{L}\int_{0}^{L}f(x)\sin\frac{n\pi x}{L}\,dx,}\\
\color{blue}{G_n}&\color{blue}{=\frac{2}{n\pi c}\int_{0}^{L}g(x)\sin\frac{n\pi x}{L}\,dx.}
\end{align}$$
Letting $c=1$, $L=1$, $f(x)=\sin x$ and $g(x)=0$ gives us the following wave (the approximation is very low):