Complex analysis to evaluate series

Hey all,

According to a theorem I have seen in class, we have

$\displaystyle \sum_{\substack{n=-\infty\\n \neq z_k}}^\infty f(n) = -\sum_{\textrm{$z_k$, the poles of $f(z)$}} Res\left(\frac{\pi \cos{(z\pi)}}{\sin{(z\pi)}}f(z), z_k\right)$

It can easily be seen that the theorem works for$\displaystyle f(n) = \frac{1}{n^2} $, but I've been trying to use it to find the exact value of $\displaystyle \sum_{n=1}^\infty \frac{(-1)^n}{n^2+1}$ without success. The poles of *f*are obviously *i* and *-i*, for which the residues are respectively $\displaystyle \frac{-\pi(-1)^i\cosh{(\pi)}}{2\sinh{(\pi)}}$ and $\displaystyle \frac{-\pi(-1)^{(-i)}\cosh{(\pi)}}{2\sinh{(\pi)}}$, which implies that $\displaystyle \sum_{n=-\infty}^\infty \frac{(-1)^n}{n^2+1} = \frac{\pi\cosh{(\pi)}}{2\sinh{(\pi)}}\left( e^{\pi} + e^{-\pi} \right)$

Of course, *f* is an even function, so $\displaystyle \sum_{n=-\infty}^\infty \frac{(-1)^n}{n^2+1} = \sum_{n=-\infty}^{-1} \frac{(-1)^n}{n^2+1} + \sum_{n=1}^\infty \frac{(-1)^n}{n^2+1} + 1 = 2\sum_{n=1}^\infty \frac{(-1)^n}{n^2+1} + 1$.

Therefore, $\displaystyle \sum_{n=1}^\infty \frac{(-1)^n}{n^2+1} = \frac{1}{2} \left( \frac{\pi\cosh{(\pi)}}{2\sinh{(\pi)}}\left( e^{\pi} + e^{-\pi} \right) - 1 \right) = 17.77673189...$

But, when I approximate the sum in Maple or MATLAB, I get another answer (which is the right one): -0.3639849730...

Does anyone have an idea of what I have done wrong?

Thank you all!!