Solution (source code)

= Solution

For the two travelling profiles, the <initial conditions> imply
$$
f(x)+g(x)=\cos^2(x/2),\qquad -vf'(x)+vg'(x)=0.
$$
Since $v\ne0$, $g-f$ is constant. One may therefore choose
$$
f(x)=\tfrac12\cos^2(x/2)+C,\qquad
g(x)=\tfrac12\cos^2(x/2)-C,
$$
where the constants cancel in the sum. The <D'Alembert formula> then gives
$$
\begin{aligned}
\psi(x,t)&=\frac12\cos^2\left(\frac{x-vt}{2}\right)
+\frac12\cos^2\left(\frac{x+vt}{2}\right)\\
&=\boxed{\frac12+\frac12\cos x\cos(vt)}.
\end{aligned}
$$
This agrees exactly with the restricted-domain solution from part (b). The whole-line cosine profile already has zero spatial <derivative> at both $x=0$ and $x=\pi$ for every time, so its restriction satisfies the <Neumann boundary conditions> without further modification.