Solution (source code)

= Solution

At $t=0$, the displacement expansion is $f(x)=\sum_nA_n\sin(n\pi x/L)$. <Fourier orthogonality> gives
$$
\boxed{A_n=\frac2L\int_0^Lf(x)\sin\frac{n\pi x}{L}\,dx.}
$$
Differentiating the modal solution at zero gives $g(x)=\sum_n\omega_nB_n\sin(n\pi x/L)$, so
$$
\boxed{B_n=\frac{2}{L\omega_n}\int_0^Lg(x)\sin\frac{n\pi x}{L}\,dx
=\frac{2}{cn\pi}\int_0^Lg(x)\sin\frac{n\pi x}{L}\,dx.}
$$
The factor $1/\omega_n$ is required because the derivative of $\sin(\omega_nt)$ at zero is $\omega_n$. The dimensions agree: $A_n$ and $B_n$ are displacements, while the sine coefficients of $g$ are velocities. These projections also establish uniqueness within the finite-energy solution class.