We have the following problem
\begin{cases} u_{tt}=u_{xx}\\ u_x(0,t)=u_x(\pi,t)=0\\ u(x,0)=\cos x\\ u_t(x,0)=-\cos x \end{cases}
The correct approach should be:
We have homogeneous Neumann conditions on x, so we can make the ansatz:
$$u(x,t)=\cos nx \ u(t)$$
Insert in the PDE and get the ODE:
$$u_{tt}+n^2u=0$$
This gives the eigenvalue $\lambda:=\pm in$
This gives the solution on $t$:
$$u(t)=A\cos nt + B\sin nt$$
Use Initial conditions and obtain:
$A=\cos x$ and $B=-\frac{\cos x}{n}$
So this should be the correct basis to form the general solution:
$$u(x,t)=\sum_{n=1}^\infty \cos n x \bigg(\cos nt-\frac{sin nt}{n}\bigg)\cos x$$
But somehow, this is not correct.
Where was the error made?
Thanks
You can't just plug in $u(t)$ to get $A$ and $B$. You write the full solution:$$u(x,t)=\sum_{n=-\infty}^\infty A_n\cos nx\cos nt+B_n\cos nx\sin nt$$ Now plugging in $t=0$ you get $$u(x,0)=\sum_{n=-\infty}^\infty A_n\cos nx=\cos x$$ That means $A_{-1}+A_1=1$ and all other $A_n$ are zero. Then calculate $u_t(x,t)$: $$u_t(x,t)=\sum_{n=-\infty}^\infty -nA_n\cos nx\sin nt+nB_n\cos nx\cos nt$$ Plug in $t=0$ and you get $$u_t(x,0)=\sum_{n=-\infty}^\infty nB_n\cos nx=-\cos x$$ The only terms you are allowed to keep are $n=\pm 1$, so $$-B_{-1}+B_1=-1$$