Solution (source code)

= Solution

For one real mode $y_n=A_n\sin(k_nx)\cos(\omega_nt+\phi_n)$, the kinetic and small-slope potential energy densities integrate to
$$
K_n=\frac\rho2\int_0^l y_{n,t}^2dx=\frac{\rho lA_n^2\omega_n^2}{4}\sin^2(\omega_nt+\phi_n),
$$
$$
U_n=\frac T2\int_0^l y_{n,x}^2dx=\frac{TlA_n^2k_n^2}{4}\cos^2(\omega_nt+\phi_n).
$$
Since $\rho\omega_n^2=Tk_n^2$, their sum is constant: $E_n=TlA_n^2k_n^2/4$. The initial condition has $\phi_n=0$ and $A_1=A$, $A_2=A/2$, hence
$$
\boxed{E_1=E_2=\frac{T\pi^2A^2}{4l},\qquad E_{\rm total}=\frac{T\pi^2A^2}{2l}.}
$$
Although the second mode's displacement amplitude is halved, its wavenumber and angular frequency are doubled, giving the same total energy. Orthogonality eliminates cross terms when the full string's energies are integrated.