Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Haifengl Smile Linear System Solving

From Leeroopedia


Overview

Linear System Solving is the process of finding a vector x that satisfies the equation Ax=b, where A is a known matrix and b 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 A (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 PA=LU, solving Ax=b proceeds in three steps:

  1. Permute: Pb (reorder b according to the pivot vector)
  2. Forward substitution: Solve Ly=Pb where L is lower triangular
  3. Back substitution: Solve Ux=y where U is upper triangular

yi=(Pb)ij=1i1lijyj,i=1,2,,nxi=yij=i+1nuijxjuii,i=n,n1,,1

Complexity: O(n2) for the solve phase (after O(n3) factorization).

LAPACK routine: dgetrs / sgetrs

Cholesky Solve

Given A=LLT (SPD matrix), solving Ax=b:

  1. Forward substitution: Solve Ly=b
  2. Back substitution: Solve LTx=y

Complexity: O(n2) for the solve, O(13n3) 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 (m>n), QR solves the least squares problem:

minxAxb2

Given A=QR:

  1. Apply QT: Compute QTb using dormqr/sormqr
  2. Triangular solve: Solve Rx=(QTb)1:n using dtrtrs/strtrs

The solution minimizes the residual Axb2 and is numerically more stable than the normal equations approach ATAx=ATb.

LAPACK routines: dormqr + dtrtrs / sormqr + strtrs

SVD Solve (Pseudoinverse)

For rank-deficient or ill-conditioned systems, SVD provides the most robust solution:

x=VΣ1UTb

where Σ1 is formed by inverting only the nonzero (above threshold) singular values. Small singular values (σircond) are treated as zero, providing a regularized solution.

  1. Compute UTb (project b onto left singular vectors)
  2. Divide by singular values: (Σ1UTb)i=(UTb)i/σi
  3. Compute V(Σ1UTb) (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 Ax=b:

  1. Start with initial guess x0
  2. Compute residual r0=bAx0
  3. Iterate: update xk using search directions pk derived from the residual

Key operations per iteration:

  • One matrix-vector product Ap
  • One transpose matrix-vector product ATpp
  • One preconditioner solve

Convergence criteria (controlled by itol parameter):

itol Criterion Description
1 Axb/b<tol Relative residual norm
2 A1(Axb)/A1b<tol Preconditioned residual
3 xk+1xk2<tol Solution change (L2)
4 xk+1xk<tol 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 Ax=b (exact) General-purpose; multiple right-hand sides
Cholesky SPD Ax=b (exact) Covariance systems, optimization; 2x faster than LU
QR Overdetermined (m>n) 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 Ax=b (iterative) When decomposition is too expensive; only needs Av and ATv

Multiple Right-Hand Sides

All direct solvers in Smile support solving AX=B where B is a matrix (multiple right-hand sides simultaneously). The matrix B is overwritten in-place with the solution X.

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 κ(A) 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

Categories

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment