Solution of a nonhomogeneous wave equation Consider the equation:
$$u_{tt}-u_{xx}=\cos(2t)\cos(3x)-2t,    0<x<\pi, 
t>0$$
$$u_x(0,t)=0, t\geq 0$$
$$u_x(\pi,t)=2\pi t, t\geq 0$$
$$u(x,0)=\cos^2(x), x\in [0,\pi]$$
$$u_t(x,0)=1+x^2$$
How to solve this equation?
And is the solution a classical one (= twice continuously differentiable)?
 A: First, let's find a boundary function of the form
$$ w(x,t) = 2\pi t \big(Ax^2 + Bx + C\big) $$
such that $w_x(0,t) = 0$ and $w_x(\pi,t) = 2\pi t$. Solving this you'll find $B=0$ and $A=\frac{1}{2\pi}$, giving $w(x,t) = tx^2$ ($C$ is free here, but for simplicity we can let it be $0$).
Now let $u(x,t) = tx^2 + v(x,t)$, then $v(x,t)$ solves the Neumann problem
\begin{cases} v_{tt} - v_{xx} = \cos(2t)\cos(3x) \\ 
v_x(0,t) = v_x(\pi,t) = 0 \\
v(x,0) = \cos^2 x \\
v_t(x,0) = 1 \end{cases}
The eigenfunctions in the $x$-direction that satisfies Neumann B.C.s are $X_n(x) = \cos(nx)$, so we look for a solution of the form
$$ v(x,t) = T_0(t) + \sum_{n=1}^\infty T_n(t)\cos(nx) $$
Plugging this form into the PDE for $v$ 
$$ T_0''(t) + \sum_{n=1}^\infty \big[T_n''(t) + n^2T_n(t)\big]\cos(nx) = \cos(2t)\cos(3x) $$
$$ \implies \begin{cases} T_0''(t) = 0 \\ T_3''(t) + 9T_3(t) = \cos 2t \\ T_n''(t) + n^2T_n(t) = 0, && n \ne 0, 3 \end{cases} $$
The initial conditions are given by
\begin{align} 
u(x,0) &= T_0(0) + \sum_{n=1}^\infty T_n(0)\cos(nx) = \cos^2 x = \frac12 + \frac12\cos 2x \\
u_t(x,0) &= T_0'(0) + \sum_{n=1}^\infty T_n'(0)\cos(nx) = 1
 \end{align}
$$ \implies \begin{cases} T_0(0) = \frac12, T_0'(0) = 1 \\ T_2(0) = \frac12, T_2'(0) = 0 \\ T_n(0) = T_n'(0) = 0, && n \ne 0, 2 \end{cases} $$
Solving the above IVPs we have
\begin{cases} T_0(t) = \frac12 + t \\ T_2(t) = \frac12\cos(2t) \\ T_3(t) = \frac15\cos(2t) - \frac15 \cos(3t) \\ T_n(t) = 0, && n \ne 0,2,3 \end{cases}
Putting everything together
$$ u(x,t) = tx^2 + \frac12 + t + \frac12\cos(2t)\cos(2x) + \frac15 \big(\cos(2t)-\cos(3t)\big)\cos(3x) $$
A: *

*We look for the solution u of the form $u(x, t) = v(x, t) + tx^2$.
Then the function $v(x,t)$ has to be the solution of the following problem
$$
 \left\{ 
\begin{array}{lll}
&v_{tt}-v_{xx}=\cos(2t)\cos(3x),\; 0<x<\pi,\; t>0,\\
&v_x(0,t)=0,\quad v_x(\pi,t)=0,\\
&u(x,0)=\cos^2(x),\; 0<x<\pi,\\
&u_t(x,0)=1,\; 0<x<\pi.
\end{array}
\right.
\qquad (1)
$$

*Solve the Sturm-Liouville problem
$$-X_k''=\lambda_k X_k,\;X'(0)=X'(\pi)=0.$$
The eigenvalues and the corresponding eigenfunctions are
$$\lambda_k = k^2,\quad X_k(x) = \cos(kx),\; k\ge0.$$

*We find  Fourier series expansions
$$F=\cos(2t)\cos(3x)=\sum_{k=0}^\infty F_kX_k,$$
$$f=\cos^2(x)=\frac12+\frac{\cos(2x)}{2}=\sum_{k=0}^\infty f_kX_k,$$
$$g=1=\sum_{k=0}^\infty g_kX_k.$$
$$F_k=\begin{cases} \cos(2t), \quad k=3, & \\ 0, \quad k\neq3. \end{cases}$$
$$f_k=\begin{cases} \frac12,\quad k=0\quad \text{or} \quad k=2, & \\ 0 \quad\text{ in other cases} \end{cases}$$
$$g_k=\begin{cases} 1,\quad k=0, & \\ 0,\quad k\neq0. \end{cases}$$

*The solution $v(x,t)$ of problem $(1)$ has the form
$$u=\sum_{k=0}^\infty T_k(t)X_k(x)$$
where $T_k(t)$ is solutions of ODE problems
$$T''_k(t)+\lambda_kT_k(t)=F_k,\; T_k(0)=f_k,\;T'_k(0)=g_k.$$
Then
$$T''_0=0,\;T_0(0)=\frac12,\;T'_0(0)=1\quad
\Rightarrow\quad T_0=\frac12+t$$
$$T''_2+4T_2=0,\;T_2(0)=\frac12,\;T'_2(0)=0\quad
\Rightarrow\quad T_2=\frac{\cos( 2 t)}{2}$$
$$T''_3+9T_3=\cos(2t),\;T_3(0)=T'_3(0)=0\;
\Rightarrow\; T_3=\frac{\cos(2t)-\cos(3t)}{5}$$
$$T_k=0\quad \text{in other cases}$$

*Final solution is
$$u=T_0X_0+T_2X_2+T_3X_3+tx^2\\
=\frac12+t+\frac{\cos( 2 t)}{2}\cos(2x)+\frac{\cos(2t)-\cos(3t)}{5}\cos(3x)+tx^2
$$
