<s>[INST] An exercise on the calculation of a function of operator The operator is given by
$$A=\begin{pmatrix}
1 & 0 & 0\\
1 & 1 & 0\\
0 & 0 & 4
\end{pmatrix}$$
I have to write down the operator $$B=\tan(\frac{\pi} {4}A)$$
I calculate $$\mathcal{R} (z) =\frac{1}{z\mathbb{1}-A}=\begin{pmatrix} 
\frac{1}{z-1} & 0 & 0\\
\frac{1}{(z-1)^2} & \frac{1}{z-1} & 0\\
0 & 0 & \frac{1}{z-4}\end{pmatrix} $$
Now the B operator is given by:
$$B=\begin{pmatrix}
Res_{z=1}\frac{\tan(\frac{\pi}{4}z)}{z-1} & 0 & 0\\
Res_{z=1}\frac{\tan(\frac{\pi}{4}z)}{(z-1)^2} & Res_{z=1}\frac{\tan(\frac{\pi}{4}z)}{z-1} & 0\\
0 & 0 & Res_{z=4}\frac{\tan(\frac{\pi}{4}z)}{z-4}
\end{pmatrix} $$
For me the result should be
$$ B=\begin{pmatrix}
1 & 0 & 0\\
\frac{\pi}{2} & 1 & 0\\
0 & 0 & 0\end{pmatrix}$$
But the exercise gives as  solution:
$$ B=\begin{pmatrix}
1 & 0 & 0\\
\frac{\pi}{4} & 1 & 0\\
0 & 0 & 1\end{pmatrix}$$
Where is the error?
Thank you and sorry for bad English 
 [/INST] Can you try using the exponent formula for matrices? It works the same way: $$e^{A} =1+A + \frac{1}{2!} A^2+\dots \in \text{GL}(2, \mathbb{R})$$
The exponent of any matrix is an invertible $3\times 3$ matrix.
if we need a tangent function defined on matrices all of $\tan, \sin, \cos$ can be done with exponent function:
$$ \tan A = \frac{e^{iA}-e^{-iA}}{e^{iA}+e^{-iA}}$$
What remains is to find the matrix exponent of the lower-triangular matrix.
if we can write $A=A_0+N$ with $A_0$ diagonal and $N$ nilpotent (here $N^3=0$), then $e^{A}=e^{A_0}e^{N}$. Indeed 
$$A=
\begin{pmatrix}
1 & 0 & 0\\
1 & 1 & 0\\
0 & 0 & 4
\end{pmatrix}=
\begin{pmatrix}
1 & 0 & 0\\
0 & 1 & 0\\
0 & 0 & 4
\end{pmatrix}+
\begin{pmatrix}
0 & 0 & 0\\
1 & 0 & 0\\
0 & 0 & 0
\end{pmatrix}=A_0+N
 $$
This gets you started.
</s>