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)}$.
  • $\begingroup$ Maybe you could give an example of such a function f(z) and the expected output? $\endgroup$
    – bill s
    Nov 4 '16 at 13:54
  • $\begingroup$ @bills I expanded my question. $\endgroup$
    – Casimir
    Nov 4 '16 at 14:24
  • $\begingroup$ In Mathematica InputForm notation preferably (to expand on the request by @bill s) $\endgroup$ Nov 4 '16 at 14:38
  • $\begingroup$ 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. $\endgroup$ Nov 4 '16 at 14:43
  • 2
    $\begingroup$ 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)} $\endgroup$ Nov 4 '16 at 15:15

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.


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

enter image description here

enter image description here

  • $\begingroup$ Have you tried h[z_] := (z - a)^3 ? $\endgroup$
    – user64494
    Nov 4 '16 at 16:54
  • $\begingroup$ 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. $\endgroup$
    – Casimir
    Nov 4 '16 at 17:03
  • $\begingroup$ @Casimir -- That's exactly why I asked for an example. You can generailize to higher orders yourself. $\endgroup$
    – bill s
    Nov 4 '16 at 17:04
  • $\begingroup$ @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? $\endgroup$
    – Casimir
    Nov 4 '16 at 17:06

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)

  • $\begingroup$ 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. $\endgroup$
    – Casimir
    Nov 4 '16 at 14:47
  • 1
    $\begingroup$ @Casimir: These demands should be stated in your question. $\endgroup$
    – user64494
    Nov 4 '16 at 15:05
  • $\begingroup$ I thought I did. That's what I tried to signify with words like 'automatically', 'at all poles' and 'list or table'. $\endgroup$
    – Casimir
    Nov 4 '16 at 15:07
  • $\begingroup$ @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. $\endgroup$
    – user64494
    Nov 4 '16 at 16:09
  • $\begingroup$ @Casimir - One of the difficulties is the following: the command Residue[1/(z^2 - 2*a), {z, N[Sqrt[2]]*Sqrt[a]}] outputs 0. $\endgroup$
    – user64494
    Nov 4 '16 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.