Wave equation with piecewise-defined Cauchy data Consider the following Cauchy problem
$$u_{tt} - c^2u_{xx} = 0$$
$$u(x,0) = 
\left\{\begin{matrix} 
0 & \text{for}~x<0, \\ 
x^2 & \text{for}~x\geq0
\end{matrix}\right.
$$
$$u_t(x,0) = 0$$
The D'Alembert solution is $u(x,t) = \frac 12(f(x-ct) + f(x + ct))$ which eventually leads to $u(x,t) = x^2 + c^2t^2 \quad\text{for} \ x \geq 0$. However, the answer sheet for the exercise gives the following solution for t>0:
$$u(x,t) = 
\left\{\begin{matrix}
-x^2 -c^2t^2 & \text{for}~x<-ct, \\
2ctx & \text{for}~-ct \geq x < ct \\
x^2 + c^2t^2 & \text{for}~x \geq ct
\end{matrix}\right.
$$
Please somebody show me how to acquire this solution because I'm stumped!
 A: Using d'Alembert's formula, we have
$$
\begin{aligned}
u(x,t) &= \tfrac{1}{2}\left[ u(x-ct,0)+u(x+ct,0) \right] \\
&= \tfrac{1}{2}\left[ (x-ct)^2 {\bf 1}_{x\geq ct} + (x+ct)^2 {\bf 1}_{x\geq -ct} \right]
\end{aligned}
$$
i.e.
$$
u(x,t) = \left\lbrace\begin{aligned}
&0 && \text{if}\quad x < {-c}t \\
&\tfrac12 (x+ct)^2 && \text{if}\quad {-c}t\leq x < ct \\
& x^2 + c^2 t^2 && \text{if}\quad {c}t\leq x
\end{aligned}\right.
$$
which is naturally in agreement with the prescribed initial conditions $u(x,0) = x^2 {\bf 1}_{x\geq 0}$ and $u_t (x,0) = 0$.
Note that the proposed "answer" in OP doesn't match these initial conditions. Indeed, by setting $t=0$ in the proposed "solution", we get $u(x,0) = x^2 ({\bf 1}_{x\geq 0} - {\bf 1}_{x< 0})$ and $u_t (x,0) = 0$.
A: Given that
$$u(x,t) = \frac {1}{2}\big(u(x-ct,0) + u(x + ct,0)\big) = \frac {1}{2}\big(u(x-ct) + u(x + ct)\big)$$
You should break up the analysis into three cases substituting $(x−ct)$ and $(x+ct)$ for $x$ to evaluate
$$u(x-ct) = 
\left\{\begin{matrix} 
0 & \text{for}~x<ct, \\ 
(x-ct)^2 & \text{for}~x\geqslant ct
\end{matrix}\right.
$$
$$u(x+ct) = 
\left\{\begin{matrix} 
0 & \text{for}~x<-ct, \\ 
(x+ct)^2 & \text{for}~x \geqslant -ct
\end{matrix}\right.
$$
$\def\d{\mathrm{d}}$By d'Alembert's formula,
For $x < -ct$,$$
u(x, t) = \frac {1}{2}\big(u(x-ct) + u(x + ct)\big)= \frac {1}{2}\big(0 + 0\big)=0
$$
For $-ct \leqslant x < ct$,$$
u(x, t) = \frac {1}{2}\big(u(x-ct) + u(x + ct)\big)= \frac {1}{2}\big(0 + (x + ct)^2\big)=\frac {1}{2}\big(x + ct\big)^2
$$
For $x \geqslant ct$,$$
u(x,t)=\frac {1}{2}\big(u(x-ct) + u(x + ct)\big)=\frac{1}{2}\big((x-ct)^2 + (x + ct)^2\big)=x^2+c^2t^2
$$
Therefore$$
u(x, t) = \begin{cases}
0; & x < -ct\\
\frac {1}{2}\big(x + ct\big)^2; & -ct \leqslant x < ct\\
x^2+c^2t^2; & x \geqslant ct
\end{cases}
$$
