# residue

Partial fraction expansion (partial fraction decomposition)

## Syntax

``````[r,p,k] = residue(b,a)``````
``````[b,a] = residue(r,p,k)``````

## Description

example

``````[r,p,k] = residue(b,a)``` finds the residues, poles, and direct term of a Partial Fraction Expansion of the ratio of two polynomials, where the expansion is of the form$\frac{b\left(s\right)}{a\left(s\right)}=\frac{{b}_{m}{s}^{m}+{b}_{m-1}{s}^{m-1}+\dots +{b}_{1}s+{b}_{0}}{{a}_{n}{s}^{n}+{a}_{n-1}{s}^{n-1}+\dots +{a}_{1}s+{a}_{0}}=\frac{{r}_{n}}{s-{p}_{n}}+...+\frac{{r}_{2}}{s-{p}_{2}}+\frac{{r}_{1}}{s-{p}_{1}}+k\left(s\right).$The inputs to `residue` are vectors of coefficients of the polynomials `b = [bm ... b1 b0]` and ```a = [an ... a1 a0]```. The outputs are the residues ```r = [rn ... r2 r1]```, the poles `p = [pn ... p2 p1]`, and the polynomial `k`. For most textbook problems, `k` is `0` or a constant.```

example

``````[b,a] = residue(r,p,k)``` converts the partial fraction expansion back to the ratio of two polynomials and returns the coefficients in `b` and `a`.```

## Examples

collapse all

Find the partial fraction expansion of the following ratio of polynomials F(s) using `residue`

`$F\left(s\right)=\frac{b\left(s\right)}{a\left(s\right)}=\frac{-4s+8}{{s}^{2}+6s+8}.$`

```b = [-4 8]; a = [1 6 8]; [r,p,k] = residue(b,a)```
```r = 2×1 -12 8 ```
```p = 2×1 -4 -2 ```
```k = [] ```

This represents the partial fraction expansion

`$\frac{-4s+8}{{s}^{2}+6s+8}=\frac{-12}{s+4}+\frac{8}{s+2}.$`

Convert the partial fraction expansion back to polynomial coefficients using `residue`.

`[b,a] = residue(r,p,k)`
```b = 1×2 -4 8 ```
```a = 1×3 1 6 8 ```

This result represents the original fraction F(s).

If the degree of the numerator is equal to the degree of the denominator, the output `k` can be nonzero.

Find the partial fraction expansion of a ratio of two polynomials F(s) with complex roots and equal degree of numerator and denominator, where F(s) is

`$F\left(s\right)=\frac{b\left(s\right)}{a\left(s\right)}=\frac{2{s}^{3}+{s}^{2}}{{s}^{3}+s+1}.$`

```b = [2 1 0 0]; a = [1 0 1 1]; [r,p,k] = residue(b,a)```
```r = 3×1 complex 0.5354 + 1.0390i 0.5354 - 1.0390i -0.0708 + 0.0000i ```
```p = 3×1 complex 0.3412 + 1.1615i 0.3412 - 1.1615i -0.6823 + 0.0000i ```
```k = 2 ```

`residue` returns the complex roots and poles, and a constant term in `k`, representing the partial fraction expansion

`$F\left(s\right)=\frac{b\left(s\right)}{a\left(s\right)}=\frac{2{s}^{3}+{s}^{2}}{{s}^{3}+{s}^{2}+1}=\frac{0.5354+1.0390i}{s-\left(0.3412+1.1615i\right)}+\frac{0.5354-1.0390i}{s-\left(0.3412-1.1615i\right)}+\frac{-0.0708}{s+0.6823}+2.$`

When the degree of the numerator is greater than the degree of the denominator, the output `k` is a vector that represents the coefficients of a polynomial in s.

Perform the following partial fraction expansion of F(s) using `residue`.

`$F\left(s\right)=\frac{b\left(s\right)}{a\left(s\right)}=\frac{2{s}^{4}+s}{{s}^{2}+1}=\frac{0.5-1i}{s-1i}+\frac{0.5+1i}{s+1i}+2{s}^{2}-2.$`

```b = [2 0 0 1 0]; a = [1 0 1]; [r,p,k] = residue(b,a)```
```r = 2×1 complex 0.5000 - 1.0000i 0.5000 + 1.0000i ```
```p = 2×1 complex 0.0000 + 1.0000i 0.0000 - 1.0000i ```
```k = 1×3 2 0 -2 ```

`k` represents the polynomial $2{s}^{2}-2$.

## Input Arguments

collapse all

Coefficients of the polynomial in the numerator, specified as a vector of numbers representing the coefficients of the polynomial in descending powers of s.

Data Types: `single` | `double`
Complex Number Support: Yes

Coefficients of the polynomial in the denominator, specified as a vector of numbers representing the coefficients of the polynomial in descending powers of s.

Data Types: `single` | `double`
Complex Number Support: Yes

## Output Arguments

collapse all

Residues of partial fraction expansion, returned as a column vector of numbers.

Poles of partial fraction expansion, returned as a column vector of numbers.

Direct term, returned as a row vector of numbers that specify the coefficients of the polynomial in descending powers of s.

collapse all

### Partial Fraction Expansion

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\left(s\right)}{a\left(s\right)}=\frac{{r}_{m}}{s-{p}_{m}}+\frac{{r}_{m-1}}{s-{p}_{m-1}}+\dots +\frac{{r}_{0}}{s-{p}_{0}}+k\left(s\right)$`

This sum is called the partial fraction expansion of F. The values rm,...,r1 are the residues, the values pm,...,p1 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(j) = ... = p(j+m-1)` is a pole of multiplicity `m`, then the expansion includes terms of the form

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

## Algorithms

`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.

## References

[1] Oppenheim, A.V. and R.W. Schafer. Digital Signal Processing. Prentice-Hall, 1975, p. 56.