# residue

## 语法

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

## 说明

``[r,p,k] = residue(b,a)` 计算以如下形式展开的两个多项式之比的 部分分式展开式 的留数、极点和直项$\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).$`residue` 的输入是由多项式 `b = [bm ... b1 b0]` 和 `a = [an ... a1 a0]` 的系数组成的向量。输出为留数 `r = [rn ... r2 r1]`、极点 `p = [pn ... p2 p1]` 和多项式 `k`。对于大多数教科书问题，`k` 为 `0` 或常量。`

``[b,a] = residue(r,p,k)` 将部分分式展开式转换回两个多项式之比，并将系数返回给 `b` 和 `a`。`

## 示例

`$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 = [] ```

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

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

`$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` 返回代表部分分式展开式的复数根和极点，以及常项 `k`

`$F\left(s\right)=\frac{b\left(s\right)}{a\left(s\right)}=\frac{2{s}^{3}+{s}^{2}}{{s}^{3}+s+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.$`

`$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` 代表多项式 $2{s}^{2}-2$

## 详细信息

### 部分分式展开式

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

`$\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)$`

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

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

`$\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}}.$`

## 算法

`residue` 首先会使用 `roots` 获取极点。接下来，如果分式不正确，则使用执行多项式长除法的 `deconv` 计算直项 `k`。最后，`residue` 通过计算移除了各个根的多项式来确定留数。对于重复根，`resi2` 计算重复根位置处的留数。

## 参考

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