How to solve equation with Fourier's method of separation of variables $\frac{\partial^2 u}{\partial t^2} - 4 \frac{\partial^2 u}{\partial x^2} = 0$
$0< x< 1,t> 0$
Boundary conditions $\frac{\partial u }{\partial x}(0,t)=0$,  $\frac{\partial u }{\partial x}(1,t)=0$
Initial conditions $u(x,0)=0$,  $\frac{\partial u }{\partial t}(x,0)=cos^2(\pi x)$
with solution $\frac{t}{2} + \frac{1}{8 \pi}cos(2 \pi x)sin(4 \pi t)$
I tried with:
$X(x)T''(t)=4X''(x)T(t)=\lambda$
$X'' - \lambda X =0$ 
a) There is no solution for $\lambda = K^2$
b) For $\lambda =0$ , $X(x)=A+Bx$   ,   $X'(x)=B$ 
With the boundary conditions $0=B$ and there's a solution $X=A$
c) For $\lambda = -K^2$  , $X=A  cos(Kx) + B sin (kx)$
$X'=-AKsin(Kx) + BK cos(Kx)$ , using the boundary conditions $B=0$ ,  $X_n=Acos(n \pi)x$ and $\lambda = - \pi^2 n^2$
Solving for $T(t)$  ,  $T''-4 \lambda T =0$
a) For $\lambda = 0$ , $T= C + Dt$
A solution $u(x,t)= A \cdot (C+Dt) = C+Dt$ , using the initial conditions, $C=0$ ,  $u'(x,t)=D = cos^2( \pi x)$ and $u(x,t)=cos^2 (\pi x)t$
b) for $\lambda = - \pi^2 n^2$
$T_n= A cos(2n \pi)t + B sin(2n \pi)t$
The solution $u_n(x,t)= A cos(n \pi x)cos(2n \pi)t + B cos(n \pi x)sin(2n \pi)t$
Applying Fourier series $u(x,t) = \sum_{n=1}^{n= \infty} a_n cos(n \pi x)cos(2n \pi)t + b_n cos(n \pi x)sin(2n \pi)t$
Using the initial conditions $u(x,t) =\sum_{n=1}^{n= \infty} a_n cos(n \pi x) $
$a_n = \frac{<0,cos(n \pi x)>}{<cos(n \pi x),cos(n \pi x)>} = 0$
$u'(x,t) = \sum_{n=1}^{n= \infty} -a_n cos(n \pi x)2n \pi sin(2n \pi)t + b_n cos(n \pi x)2n \pi cos(2n \pi)t$
$b_n = \frac{<cos^2 \pi x,cos(n \pi x)>}{<cos(n \pi x),cos(n \pi x)>} = 0$
The solution that I get is $u(x,t)=cos^2 (\pi x)t$
EDIT:
How can I find $A_n$ using using Fourier coefficient formula?. That's the only way I've been taught to find it. In this case  $A_n =\ \frac {\int_{0}^{1}cos^2(\pi x)cos(n \pi x)}{\int_{0}^{1}cos(n \pi x)^2}$  $\int_{0}^{1}cos^2(\pi x)cos(n \pi x) = \int_{0}^{1}1/2 \cdot cos(n \pi x) + \ 1/2 \cdot \int_{0}^{1}cos(2 \pi x)cos(n \pi x).$
$\int_{0}^{1}1/2 \cdot cos(n \pi x) = 1/2 \cdot [_0^1 \frac {sin(n \pi x)}{n \pi} = 0 $
Using the product sum formula $\cos x \cos y=\frac{1}{2}[\cos(x-y)+\cos(x+y)]\\$
The second integral $\ 1/2 \cdot \int_{0}^{1}cos(2 \pi x)cos(n \pi x)= 1/2   \cdot \int_{0}^{1}cos(\pi x(2-n)  )+ \int_{0}^{1}cos(\pi x(2+n)  ) = \ 1/2 \cdot[_0^1 \frac {sin(\pi x (2-n)}{\pi(2-n)}=0+ \ 1/2 \cdot[_0^1 \frac {sin(\pi x (2+n)}{\pi(2+n)}=0 $
 A: The separation of variables problem for $u(x,t)=X(x)T(t)$ is
$$
             \frac{T''}{T} = \lambda = 4\frac{X''}{X}, \\
               X'(0)=X'(1)=0 \\
               T(0)=0.
$$
To normalize the soutions $X$, assume that $X(0)=1$. The solutions of
$$
             X''+\frac{\lambda}{4}X=0 \\
             X(0)=1,\; X'(0)=0
$$
have the form
$$
               X(x)=\cos\frac{\sqrt{\lambda}}{2}x.
$$
This works for $\lambda=0$ as well, to give the solution $X(x)=1$. $\lambda$ is an eigenvalue iff the above solution satisfies $X'(0)=0$, which results in the eigenvalue equation
$$
              \frac{\sqrt{\lambda}}{2}\sin\frac{\sqrt{\lambda}}{2}=0.
$$
The valid eigenvalues are
$$
         \frac{\sqrt{\lambda}}{2}=n\pi,\;\;\; n=0,1,2,3,\cdots,\\
         \lambda_n = 4n^2\pi^2,\;\; n=0,1,2,3,\cdots.
$$
The corresponding eigenfunctions are
$$
         X_n(x) = \cos(n\pi x),\;\;\; n=0,1,2,3,\cdots.
$$
Because $T(0)=0$, the solutions in $t$ are
\begin{align}
        T_0(t) & = A_0 t \\
        T_n(t) & = A_n\sin(2n\pi t), \; \; n \ge 1.
\end{align}
The general solution becomes
$$
         u(x,t)= A_0t+\sum_{n=1}^{\infty}A_n\sin(2n\pi t)\cos(n\pi x).
$$
The coefficients $A_n$ are determined by the initial conditions
$$
    \cos^2(\pi x) = u_t(x,0)= A_0+\sum_{n=1}^{\infty}2n\pi A_n\cos(n\pi x) \\
    \frac{1}{2}(\cos(2\pi x)+1) = A_0+\sum_{n=1}^{\infty}2\pi n A_n\cos(n\pi x).
$$
From this you can see that all $A_n$ are $0$ except,
$$
           A_0=\frac{1}{2},\;\; A_2=\frac{1}{8\pi}
$$
So, the solution is
$$
     u(x,t) = \frac{t}{2}+\frac{1}{8\pi}\sin(4\pi t)\cos(2\pi x).
$$
