Cosine of a $2 \times 2$ non-diagonalisable matrix Given
$$A = \begin{bmatrix}
      \pi-1 &     1\\
         -1 & \pi+1
      \end{bmatrix}$$
I need to calculate its cosine, $\cos(A)$. Typically, I use diagonalisation to approach this type of problems:
$$\cos(A) = P \cos(D) P^{-1}$$
However, in this problem, the eigenvalues of the matrix are equal: $\lambda_1=\pi, \lambda_2=\pi$. Thus, there are no two linearly independent vectors and the method will not work.
Are there any alternative approaches? 
Besides MacLaurin series expansion of $\cos(A)$, which does not work either since $A$ does not turn into a zero matrix at some point when multiplied by itself $n$ times.

When working this sort of thing out I usually take powers of the matrix and look for a pattern. In this case I found, 
$$ M^0 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}$$
$$ M^1 = \begin{bmatrix} \pi -1  & 1 \\ -1 & \pi+1 \end{bmatrix}$$
$$ M^2 = \begin{bmatrix} \pi^2 - 2\pi & 2\pi \\ -2\pi & \pi^2 + 2\pi\end{bmatrix}$$
$$ M^3 = \begin{bmatrix} \pi^3 - 3\pi & 3\pi^2 \\ -3\pi & \pi^3 + 3\pi^2\end{bmatrix}$$
$$ M^4 = \begin{bmatrix} \pi^4 - 4\pi^3 & 4\pi^3 \\ -4\pi^3 & \pi^4 + 4\pi^3 \end{bmatrix},$$
This leads me to suspect that for $p\geq 0$ we have,
$$ \boxed{M^p = \begin{bmatrix} \pi^p - p \pi^{p-1} & p \pi^{p-1} \\ -p \pi^{p-1} & \pi^p + p \pi^{p-1} \end{bmatrix}}$$
This can be confirmed by a simple induction proof. Now we can evaluate $\cos(M)$ using the series definition of $\cos$
$$ \cos(M) = \sum_{p=0}^\infty (-1)^p\frac{M^{2p}}{(2p)!}$$
$$ = \sum_{p=0}^\infty \frac{(-1)^p}{(2p)!}\begin{bmatrix} \pi^{2p} - 2p \pi^{2p-1} & 2p \pi^{2p-1} \\ -2p \pi^{2p-1} & \pi^{2p} + 2p \pi^{2p-1} \end{bmatrix}$$

Bringing the summation inside the matrix entries we get the following, 
$$ \cos(M) = \begin{bmatrix} \sum_{p=0}^\infty \frac{(-1)^p \pi^{2p}}{(2p)!} - \sum_{p=0}^\infty \frac{(-1)^p 2p \pi^{2p-1}}{(2p)!} & \sum_{p=0}^\infty \frac{(-1)^p 2p \pi^{2p-1}}{(2p)!} \\ - \sum_{p=0}^\infty \frac{(-1)^p 2p \pi^{2p-1}}{(2p)!} & 
 \sum_{p=0}^\infty \frac{(-1)^p \pi^{2p}}{(2p)!} + \sum_{p=0}^\infty \frac{(-1)^p 2p \pi^{2p-1}}{(2p)!} \end{bmatrix}  $$
So we need to evaluate the following sums, 
$$ S_1 = \sum_{p=0}^\infty \frac{(-1)^p \pi^{2p}}{(2p)!} = \cos(\pi),$$
and
$$ S_2 = \sum_{p=0}^\infty \frac{(-1)^p 2p \pi^{2p-1}}{(2p)!}  = \frac{d}{d\pi} \sum_{p=0}^\infty \frac{(-1)^p  \pi^{2p}}{(2p)!} = -\sin(\pi)$$
We now have
$$ \cos(M) = \begin{bmatrix} \cos(\pi) - \sin(\pi) & \sin(\pi) \\ -\sin(\pi) & \cos(\pi) + \sin(\pi) \end{bmatrix} $$ 
