Principle:Haifengl Smile Linear System Solving
Overview
Linear System Solving is the process of finding a vector that satisfies the equation , where is a known matrix and is a known vector. This is one of the most fundamental problems in scientific computing, appearing in regression, optimization, physics simulation, signal processing, and machine learning.
Smile provides two classes of solvers:
- Direct solvers that first decompose (LU, QR, Cholesky, SVD) and then solve via substitution. These are exact (up to floating-point precision) and have predictable cost.
- Iterative solvers (Biconjugate Gradient) that approximate the solution through successive refinement. These are efficient for large sparse systems where direct decomposition is too expensive.
Theoretical Basis
Direct Solving via Decomposition
Direct methods transform the original system into a sequence of easily solvable triangular systems.
LU Solve
Given , solving proceeds in three steps:
- Permute: (reorder according to the pivot vector)
- Forward substitution: Solve where is lower triangular
- Back substitution: Solve where is upper triangular
Complexity: for the solve phase (after factorization).
LAPACK routine: dgetrs / sgetrs
Cholesky Solve
Given (SPD matrix), solving :
- Forward substitution: Solve
- Back substitution: Solve
Complexity: for the solve, for factorization.
Advantage over LU: Approximately 2x faster because Cholesky factors are half the size and no pivoting is required.
LAPACK routine: dpotrs / spotrs
QR Solve (Least Squares)
For overdetermined systems (), QR solves the least squares problem:
Given :
- Apply : Compute using
dormqr/sormqr - Triangular solve: Solve using
dtrtrs/strtrs
The solution minimizes the residual and is numerically more stable than the normal equations approach .
LAPACK routines: dormqr + dtrtrs / sormqr + strtrs
SVD Solve (Pseudoinverse)
For rank-deficient or ill-conditioned systems, SVD provides the most robust solution:
where is formed by inverting only the nonzero (above threshold) singular values. Small singular values () are treated as zero, providing a regularized solution.
- Compute (project onto left singular vectors)
- Divide by singular values:
- Compute (expand in right singular vector basis)
Advantages: Works for any matrix (including singular and rank-deficient); provides the minimum-norm solution when the system is underdetermined.
Iterative Solving
Biconjugate Gradient Method (BiCG)
For large sparse systems where direct decomposition is impractical, the Biconjugate Gradient method iteratively refines an approximate solution. Given :
- Start with initial guess
- Compute residual
- Iterate: update using search directions derived from the residual
Key operations per iteration:
- One matrix-vector product
- One transpose matrix-vector product
- One preconditioner solve
Convergence criteria (controlled by itol parameter):
| itol | Criterion | Description |
|---|---|---|
| 1 | Relative residual norm | |
| 2 | Preconditioned residual | |
| 3 | Solution change (L2) | |
| 4 | Solution change (Linf) |
Preconditioning: The default preconditioner is Jacobi (diagonal scaling), which divides each equation by its diagonal element. Better preconditioners (ILU, SSOR) can be supplied via the Preconditioner interface.
Choosing the Right Solver
| Solver | Matrix Type | System Type | When to Use |
|---|---|---|---|
| LU | Square, non-singular | (exact) | General-purpose; multiple right-hand sides |
| Cholesky | SPD | (exact) | Covariance systems, optimization; 2x faster than LU |
| QR | Overdetermined () | Least squares | Regression, fitting; more stable than normal equations |
| SVD | Any (including rank-deficient) | Least squares / min-norm | Ill-conditioned systems; need rank information |
| BiCG | Large, sparse | (iterative) | When decomposition is too expensive; only needs and |
Multiple Right-Hand Sides
All direct solvers in Smile support solving where is a matrix (multiple right-hand sides simultaneously). The matrix is overwritten in-place with the solution .
This is more efficient than solving individual systems because:
- The decomposition is computed once
- LAPACK can optimize memory access patterns for the block solve
Numerical Stability Considerations
- LU with pivoting: Partial pivoting ensures stability for most practical matrices, but can amplify errors for pathological cases.
- QR: Always backward stable; preferred when numerical accuracy is paramount.
- Cholesky: The most stable option for SPD matrices because it exploits positive definiteness.
- SVD: The most robust option overall; can handle singular and near-singular matrices gracefully through thresholding.
- BiCG: Convergence depends on the condition number and the quality of the preconditioner. May stagnate for highly ill-conditioned systems.
Relationship to the Pipeline
Construction --> Arithmetic --> Decomposition --> Solving --> Result Extraction
^
|
(this principle)
Linear system solving is the fourth stage of the pipeline. It consumes decomposition results (LU, QR, Cholesky, SVD records) produced by the decomposition stage and produces solution vectors or matrices.
Related
Knowledge Sources
Domains
Linear_Algebra, Numerical_Computing, Optimization