# Can Mathematica automatically calculate and sum over residues at all poles of a (rational) function?

The title basically says it all: is there a way in Mathematica to automatically compute the residues at all poles of a function $f(z)$ and present them as well as their sum in a list or table?

A simple example would be something like $$f(z) = \frac{g(z)}{h(z)},$$ where $g(z)$ and $h(z)$ would both be polynomials. E.g. for $h(z) = (z - a)(z^2 - b^2)$, I would like Mathematica to calculate the residues at $z = a$ and $z = \pm b$ and then present them individually and what they add up to, i.e. in this case

• $\operatorname{Res}[f(z),a] = \frac{g(a)}{a^2-b^2}$,
• $\operatorname{Res}[f(z),\pm b] = \mp\frac{g(\pm b)}{2 b (a\mp b)}$,
• $\sum\limits_{z_i \in \{a,\pm b\}} \operatorname{Res}[f(z),z_i] = \frac{2 b g(a)+(a-b) g(-b)-(a+b) g(b)}{2 b (a-b) (a+b)}$.
• Maybe you could give an example of such a function f(z) and the expected output? Nov 4, 2016 at 13:54
• @bills I expanded my question. Nov 4, 2016 at 14:24
• In Mathematica InputForm notation preferably (to expand on the request by @bill s) Nov 4, 2016 at 14:38
• Also, have you tried anything, like using Residue for example? This appears to be a one-liner, if one allows for a modestly long line. Nov 4, 2016 at 14:43
• You can automate the search using Solve. Example: In[85]:= g = z^2 + 3*z - 7; h = (z - a)*(z^2 - b^2); Table[ Residue[g/h, {z, rt}], {rt, z /. Solve[Denominator[g/h] == 0, z]}] Out[86]= {(-7 + 3 a + a^2)/(a^2 - b^2), (-7 - 3 b + b^2)/( 2 b (a + b)), (7 - 3 b - b^2)/(2 (a - b) b)} Nov 4, 2016 at 15:15

## 3 Answers

The control system functionality of Mathematica can be used to find the poles of a rational function. Using Daniel's example in the comments:

f = (z^2 + 3*z - 7)/((z - a)*(z^2 - b^2));
poles = TransferFunctionPoles[TransferFunctionModel[{{f}}, z]][[1, 1]];
Sum[Residue[f, {z, res}], {res, poles}]
(-7 + 3 a + a^2)/(a^2 - b^2) + (7 - 3 b - b^2)/(2 (a - b) b) +
(-7 - 3 b + b^2)/(2 b (a + b))


Replace Sum[] with Table[] if you want the list of residues instead.

How about this?

Residue[g[z]/((z - a)*(z^2 - b^2)), {z, -b}, Assumptions -> g[-b] != 0]


g[-b]/(2 b (a + b))

Residue[g[z]/((z - a)*(z^2 - b^2)), {z, a}, Assumptions -> g[a] != 0]


g[a]/(a^2 - b^2)

• I'm aware of Mathematica's Residue function. What I'm after is a function (or a workflow consisting of multiple functions) that automatically analyzes a function to find all of its poles, then goes on to calculate the residue at each one and finally adds them up. Nov 4, 2016 at 14:47
• @Casimir: These demands should be stated in your question. Nov 4, 2016 at 15:05
• I thought I did. That's what I tried to signify with words like 'automatically', 'at all poles' and 'list or table'. Nov 4, 2016 at 15:07
• @Casimir: The word "automatically" can be interpreted in different ways. I think a procedure: a rational function (over Reals? Complexes? Integers?) -> its residua is too complicated to be realized here. Nov 4, 2016 at 16:09
• @Casimir - One of the difficulties is the following: the command Residue[1/(z^2 - 2*a), {z, N[Sqrt[2]]*Sqrt[a]}] outputs 0. Nov 4, 2016 at 17:40

This seems to solve (at least) the specific problem you posed. The Apart function does a partial fraction expansion, so you can find the roots by looking at the places where the denominators are zero. Multiplying by these roots and substituting then gives the residues.

f[z_] := g[z]/h[z];
h[z_] := ((z - a)*(z^2 - b^2));
pf = Apart[f[z], z];
tab = Table[sol = Solve[Denominator[pf[[i]]] == 0, z];
(z - First[z /. sol]) pf[[i]] /. sol, {i, Length[pf]}]//FullSimplify
Total[tab] // FullSimplify


• Have you tried h[z_] := (z - a)^3 ? Nov 4, 2016 at 16:54
• Unfortunately, the above only works for first order poles. Calculating residua at poles of order $n > 1$ involves derivatives before taking the limit, i.e. what is referred to as 'substituting' in bill s's answer. Nov 4, 2016 at 17:03
• @Casimir -- That's exactly why I asked for an example. You can generailize to higher orders yourself. Nov 4, 2016 at 17:04
• @bills I'm sorry the one I gave only contains simple poles. I wanted to keep things simple. But this should be a simple fix. Why not just use the Residue function instead of implementing the method for calculating first order poles by hand? Nov 4, 2016 at 17:06