|
1 |
| -//! Solve linear problem using LU decomposition |
2 |
| -
|
3 | 1 | use crate::{error::*, layout::MatrixLayout, *};
|
4 | 2 | use cauchy::*;
|
5 | 3 | use num_traits::{ToPrimitive, Zero};
|
6 | 4 |
|
| 5 | +#[cfg_attr(doc, katexit::katexit)] |
| 6 | +/// Solve linear equations using LU-decomposition |
| 7 | +/// |
| 8 | +/// For a given matrix $A$, LU decomposition is described as $PA = LU$ where |
| 9 | +/// |
| 10 | +/// - $L$ is lower matrix |
| 11 | +/// - $U$ is upper matrix |
| 12 | +/// - $P$ is permutation matrix represented by [Pivot] |
| 13 | +/// |
| 14 | +/// This is designed as two step computation according to LAPACK API: |
| 15 | +/// |
| 16 | +/// 1. Factorize input matrix $A$ into $L$, $U$, and $P$. |
| 17 | +/// 2. Solve linear equation $Ax = b$ or compute inverse matrix $A^{-1}$ |
| 18 | +/// using the output of LU factorization. |
| 19 | +/// |
7 | 20 | pub trait Solve_: Scalar + Sized {
|
8 |
| - /// Computes the LU factorization of a general `m x n` matrix `a` using |
9 |
| - /// partial pivoting with row interchanges. |
| 21 | + /// Computes the LU factorization of a general $m \times n$ matrix |
| 22 | + /// with partial pivoting with row interchanges. |
10 | 23 | ///
|
11 |
| - /// $ PA = LU $ |
| 24 | + /// Output |
| 25 | + /// ------- |
| 26 | + /// - $U$ and $L$ are stored in `a` after LU factorization has succeeded. |
| 27 | + /// - $P$ is returned as [Pivot] |
12 | 28 | ///
|
13 | 29 | /// Error
|
14 | 30 | /// ------
|
15 |
| - /// - `LapackComputationalFailure { return_code }` when the matrix is singular |
16 |
| - /// - Division by zero will occur if it is used to solve a system of equations |
17 |
| - /// because `U[(return_code-1, return_code-1)]` is exactly zero. |
| 31 | + /// - if the matrix is singular |
| 32 | + /// - On this case, `return_code` in [Error::LapackComputationalFailure] means |
| 33 | + /// `return_code`-th diagonal element of $U$ becomes zero. |
| 34 | + /// |
18 | 35 | fn lu(l: MatrixLayout, a: &mut [Self]) -> Result<Pivot>;
|
19 | 36 |
|
| 37 | + /// Compute inverse matrix $A^{-1}$ from the output of LU-factorization |
20 | 38 | fn inv(l: MatrixLayout, a: &mut [Self], p: &Pivot) -> Result<()>;
|
21 | 39 |
|
| 40 | + /// Solve linear equations $Ax = b$ using the output of LU-factorization |
22 | 41 | fn solve(l: MatrixLayout, t: Transpose, a: &[Self], p: &Pivot, b: &mut [Self]) -> Result<()>;
|
23 | 42 | }
|
24 | 43 |
|
|
0 commit comments