Solve the wave equation $u_{tt} = c^2 u_{xx}$ for $0 < x < \pi$, with the boundary conditions $u_x(0,t) = u_x(\pi,t) = 0$ and initial conditions $u(x,0) = \cos(x)$ and $u_t(x,0) = \cos^{2}(x)$.
Attempted solution - We know that the general solution for Neumann boundary conditions for the wave equation for $0 < x < l$ is $$u(x,t) = \frac{1}{2}A_0 + \frac{1}{2}B_0 t + \sum_{n=1}^{\infty}\left(A_n\cos \frac{n\pi c t}{l} + B_n \sin\frac{n\pi c t}{l}\right)\cos\frac{n\pi x}{l}$$ Thus in our case we have $$u(x,t) = \frac{1}{2}A_0 + \frac{1}{2}B_0 t + \sum_{n=1}^{\infty}\left(A_n\cos(nct) + B_n \sin(nct)\right)\cos(nx)$$ Note that $$A_n = \frac{2}{\pi}\int_{0}^{\pi}\phi(x)\cos(nx)dx$$ and $$B_n = \frac{2}{\pi}\int_{0}^{\pi}\phi(x)\sin(nx)dx$$
Applying the initial conditions we have
$$u(x,0) = \frac{1}{2}A_0 + \sum_{n=1}^{\infty}A_n\cos(nx) = \cos(x)$$
Thus,
$$A_0 = \frac{2}{\pi}\int_{0}^{\pi}\cos(x)dx = 0$$ and $$A_n = \frac{2}{\pi}\int_{0}^{\pi}\cos(x)\cos(nx)dx = ... = -\frac{2n\sin(n\pi)}{\pi(n^2-1)} \ \ \text{according to Wolfram}$$
Next,
$$u_t(x,0) = \frac{1}{2}B_0 + \sum_{n=1}^{\infty}B_n\times n\times c \cos(nx) = \cos^{2}(x)$$
From here onward I am not sure how to proceed and I find the answer from wolfram rather odd, if anyone can provide details of what I did wrong or should revise please let me know.
The answer should be $$u(x,t) = \frac{1}{2}t + \cos(ct)\cos(x) + \frac{1}{4c}\sin(2ct) + \cos(2x)$$