# Complex partial fraction expansion [duplicate]

I would like to have a tool for partial fraction expansion of polynomial quotient $$\frac{P(z)}{Q(z)},$$ where the order of the polynomial $$P(z)$$ is less than that of $$Q(z)$$.

The output of the function is expected to be the coefficients $$c_{ij}$$ of the expansion: $$\sum_i\sum_{j=1}^{m_i}\frac{c_{ij}}{(z-\zeta_i)^j},$$ where the sum runs over all distinct roots $$\zeta_i$$ (with multiplicity $$m_i$$) of the polynomial $$Q(z)$$.

Is there a built-in function in Mathematica which is suitable for performing the task? For a symbolic computation the list of roots of the polynomial $$Q(z)$$ can be supplied.

• (1) The Wolfram Function Repository has ExtendedApart and ApartAll. (2) A question like this should come complete with at least one specific input and desired result. May 25, 2022 at 15:56

We can factor the denominator completely and feed the result into Apart:

FullApart[expr_, x_] :=
Block[{num, den, coeff, roots},
{num, den} = Through[{Numerator, Denominator}[Together[expr]]];
(
coeff = Coefficient[den, x, Exponent[den, x]];
roots = x /. Solve[den == 0, x];

Apart[num/(coeff Times @@ (x - roots)), x]

) /; PolynomialQ[num, x] && PolynomialQ[den, x]
]


Some examples:

FullApart[(x^2 + 3 x + 1)/(x^2 + 3 x - 5)^2, x]


$$\displaystyle \scriptsize -\frac{34}{29 \sqrt{29} \left(2 x+\sqrt{29}+3\right)}+\frac{24}{29 \left(2 x+\sqrt{29}+3\right)^2}-\frac{34}{29 \sqrt{29} \left(-2 x+\sqrt{29}-3\right)}+\frac{24}{29 \left(-2 x+\sqrt{29}-3\right)^2}$$

FullApart[(x^2 + 3 x + 1)/(x^5 + 3 x - 5), x] // N // Chop


$$\scriptsize {\displaystyle -\frac{0.329077\, -0.0459113 i}{x-0.639573\, -1.20691 i}}-{\displaystyle \frac{0.329077\, +0.0459113i}{x-0.639573\, +1.20691 i}}+{\displaystyle \frac{0.0658591\, -0.0529159 i}{x+1.19386\, -0.996095i}}+{\displaystyle \frac{0.0658591\, +0.0529159 i}{x+1.19386\, +0.996095i}}+{\displaystyle \frac{0.526436}{x-1.10858}}$$

• Wow. I would never think that it is enough to represent the denominator as the product to force Apart work "correctly". Meanwhile I have solved the problem by brute force (using Residue) but of course your solution is much better.
– drer
Feb 2, 2019 at 15:43
• Interesting, I assume that approach required nesting an integral $\max\{m_i\}$ times? Feb 2, 2019 at 15:53
• I am not quite sure that I correctly understand your question. The main part was done as Table[{zi=zz[[i,1]],mi=zz[[i,2]];Table[Residue[f[z] (z-zi)^(k-1),{z,zi}],{k,mi}]},{i,Length[zz]}], where zz is the list of {root,multiplicity} elements and f[z] is the polynomial quotient.
– drer
Feb 2, 2019 at 16:34
• @drer you could integrate your input to move the order -2 term to become order -1 and so on. Your way is much cleaner and a standard approach, I’m just rusty! Feb 2, 2019 at 16:36
• @Chip Hurst How do I convert your code to either a dynamic module or Manipulate that accepts as input the rational function and outputs the result of your function FullApart Mar 14, 2020 at 14:07

Mathematica has a built-in IntegrateComplexApart method.

List@@IntegrateComplexApart[(x^2+3 x+1)/(x^2+3 x-5)^2,x]//FullSimplify//Tr


Which gives same result as @Greg's FullApart

$$\scriptsize \frac{x^2+3 x+1}{\left(x^2+3 x-5\right)^2}=\frac{24}{29 \left(2 x+\sqrt{29}+3\right)^2}+\frac{34}{\sqrt{29} \left(58 x-29 \sqrt{29}+87\right)}+\frac{24}{29 \left(-2 x+\sqrt{29}-3\right)^2}-\frac{34}{29 \sqrt{29} \left(2 x+\sqrt{29}+3\right)}$$

See the definition:

IntegrateComplexApart//GeneralUtilitiesPrintDefinitions