Main Content

# equilibrate

## 语法

``[P,R,C] = equilibrate(A)``
``[P,R,C] = equilibrate(A,outputForm)``

## 说明

``[P,R,C] = equilibrate(A)` 置换和重新缩放矩阵 `A`，使新矩阵 `B = R*P*A*C` 的对角线上元素的模为 1，非对角线上元素的模不大于 1。`
``[P,R,C] = equilibrate(A,outputForm)` 以 `outputForm` 指定的形式返回输出 `P`、`R` 和 `C`。例如，您可以将 `outputForm` 指定为 `"vector"` 以便以列向量形式返回输出。`

## 示例

```load west0479 A = west0479; c1 = condest(A)```
```c1 = 1.4244e+12 ```

```b = ones(size(A,1),1); tol = 1e-11; maxit = 450; [x,flx,~,~,rvx] = gmres(A,b,[],tol,maxit); semilogy(rvx) title('Residual Norm at Each Iteration')```

```[P,R,C] = equilibrate(A); B = R*P*A*C; c2 = condest(B)```
```c2 = 5.1036e+04 ```

```d = R*P*b; [y,fly,~,~,rvy] = gmres(B,d,[],tol,maxit); hold on semilogy(rvy) legend('Original', 'Equilibrated', 'Location', 'southeast') title('Relative Residual Norms (No Preconditioner)') hold off```

`ilu` 算出两个不同的预条件子，并将它们用作 `gmres` 的输入来再次求解问题。在绘制了平衡后范数的同一张图上，叠加绘制应用预条件子后每次迭代的残差范数，以进行比较。该图显示，基于经平衡处理的矩阵算出的预条件子极大地提高了问题的稳定性，`gmres` 在不到 30 次迭代中达到了所需的容差。

```semilogy(rvy) hold on [L1,U1] = ilu(B,struct('type','ilutp','droptol',1e-1,'thresh',0)); [yp1,flyp1,~,~,rvyp1] = gmres(B,d,[],tol,maxit,L1,U1); semilogy(rvyp1) [L2,U2] = ilu(B,struct('type','ilutp','droptol',1e-2,'thresh',0)); [yp2,flyp2,~,~,rvyp2] = gmres(B,d,[],tol,maxit,L2,U2); semilogy(rvyp2) legend('No preconditioner', 'ILUTP(1e-1)', 'ILUTP(1e-2)') title('Relative Residual Norms with ILU Preconditioner (Equilibrated)') hold off```

`A = magic(6)`
```A = 6×6 35 1 6 26 19 24 3 32 7 21 23 25 31 9 2 22 27 20 8 28 33 17 10 15 30 5 34 12 14 16 4 36 29 13 18 11 ```
`[P,R,C] = equilibrate(A)`
```P = 6×6 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 ```
```R = 6×6 0.1852 0 0 0 0 0 0 0.1749 0 0 0 0 0 0 0.1909 0 0 0 0 0 0 0.1588 0 0 0 0 0 0 0.1793 0 0 0 0 0 0 0.1966 ```
```C = 6×6 0.1799 0 0 0 0 0 0 0.1588 0 0 0 0 0 0 0.1588 0 0 0 0 0 0 0.2422 0 0 0 0 0 0 0.2066 0 0 0 0 0 0 0.2035 ```

`Bmatrix = R*P*A*C`
```Bmatrix = 6×6 1.0000 0.1471 1.0000 0.5385 0.5358 0.6031 0.1259 1.0000 0.8056 0.5509 0.6506 0.3916 0.2747 0.8485 1.0000 0.7859 0.3943 0.5825 1.0000 0.0252 0.1513 1.0000 0.6233 0.7754 1.0000 0.2562 0.0569 0.9553 1.0000 0.7295 0.1061 0.9988 0.2185 1.0000 0.9341 1.0000 ```

`[p,r,c] = equilibrate(A,"vector")`
```p = 6×1 5 6 4 1 3 2 ```
```r = 6×1 0.1852 0.1749 0.1909 0.1588 0.1793 0.1966 ```
```c = 6×1 0.1799 0.1588 0.1588 0.2422 0.2066 0.2035 ```

`Bvector = r.*A(p,:).*c'`
```Bvector = 6×6 1.0000 0.1471 1.0000 0.5385 0.5358 0.6031 0.1259 1.0000 0.8056 0.5509 0.6506 0.3916 0.2747 0.8485 1.0000 0.7859 0.3943 0.5825 1.0000 0.0252 0.1513 1.0000 0.6233 0.7754 1.0000 0.2562 0.0569 0.9553 1.0000 0.7295 0.1061 0.9988 0.2185 1.0000 0.9341 1.0000 ```

`norm(Bmatrix - Bvector)`
```ans = 0 ```

## 输入参数

`A` 为稀疏矩阵时，输出 `P``R``C` 也为稀疏矩阵。

• `"matrix"` - `P``R``C` 是矩阵，满足 `B = R*P*A*C`

• `"vector"` - `P``R``C` 是列向量，满足 `B = R.*A(P,:).*C'`

## 参考

[1] Duff, I. S., and J. Koster. “On Algorithms For Permuting Large Entries to the Diagonal of a Sparse Matrix.” SIAM Journal on Matrix Analysis and Applications 22, no. 4 (January 2001): 973–96.