Consider the fraction *F*(*s*) of
two polynomials *b* and *a* of degree *n* and *m*,
respectively

$$F\left(s\right)=\frac{b\left(s\right)}{a\left(s\right)}=\frac{{b}_{n}{s}^{n}+\dots +{b}_{2}{s}^{2}+{b}_{1}s+{b}_{0}}{{a}_{m}{s}^{m}+\dots +{a}_{2}{s}^{2}+{a}_{1}s+{a}_{0}}.$$

The fraction *F*(*s*) can
be represented as a sum of simple fractions

$$\frac{b(s)}{a(s)}=\frac{{r}_{1}}{s-{p}_{1}}+\frac{{r}_{2}}{s-{p}_{2}}+\dots +\frac{{r}_{n}}{s-{p}_{n}}+k(s)$$

This sum is called the partial fraction expansion of *F*.
The values *r*_{m},...,*r*_{1} are
the residues, the values *p*_{m},...,*p*_{1} are
the poles, and *k*(*s*) is
a polynomial in *s*. For most textbook problems, *k*(*s*)
is 0 or a constant.

The number of poles `n`

is

n = length(a)-1 = length(r) = length(p)

The direct term vector is empty if `length(b)`

`<`

`length(a)`

;
otherwise

length(k) = length(b)-length(a)+1

If `p(i) = ... = p(i+j-1)`

is a pole of multiplicity `j`

,
then the expansion includes terms of the form

$$\frac{{r}_{j}}{s-{p}_{j}}+\frac{{r}_{j+1}}{{(s-{p}_{j})}^{2}}+\dots +\frac{{r}_{j+m-1}}{{(s-{p}_{j})}^{m}}.$$

`residue`

first obtains the poles using `roots`

.
Next, if the fraction is nonproper, the direct term `k`

is
found using `deconv`

, which performs polynomial long
division. Finally, `residue`

determines the residues
by evaluating the polynomial with individual roots removed. For repeated
roots, `resi2`

computes the residues at the repeated
root locations.

Numerically, the partial fraction expansion of a ratio of polynomials
represents an ill-posed problem. If the denominator polynomial, *a*(*s*),
is near a polynomial with multiple roots, then small changes in the
data, including roundoff errors, can result in arbitrarily large changes
in the resulting poles and residues. Problem formulations making use
of state-space or zero-pole representations are preferable.