Direct solvers, Krylov iterations, eigenvalue routines, SVD, and matrix functions use explicit numerical routine names. Operator arguments enter where only the action (y = Ax) is required.
Dense Direct Solve
A(0, 0) = 4.0; A(0, 1) = 1.0; A(0, 2) = 0.0;
A(1, 0) = 1.0; A(1, 1) = 3.0; A(1, 2) = 1.0;
A(2, 0) = 0.0; A(2, 1) = 1.0; A(2, 2) = 2.0;
void lu_solve(const LUResult &f, const Vector &b, Vector &x)
Solve from a precomputed factorization.
LUResult lu(const Matrix &A, Backend backend=lapack_backend)
Umbrella include for the numerics library.
Use lu_solve(F, B, X) for multiple right-hand sides after one factorization.
For \(A=A^T>0\):
SPDMatrix< Matrix > make_spd(Matrix A, real tol=1e-12)
CholeskyResult cholesky(const linalg::SPDMatrix< Matrix > &A)
void cholesky_solve(const CholeskyResult &f, const Vector &b, Vector &x)
Use num::linalg::assume_spd(A) when the construction of \(A\) already guarantees symmetry and positive definiteness.
Least Squares
A(0, 0) = 1.0; A(0, 1) = 0.0;
A(1, 0) = 1.0; A(1, 1) = 1.0;
A(2, 0) = 1.0; A(2, 1) = 2.0;
A(3, 0) = 1.0; A(3, 1) = 3.0;
void qr_solve(const QRResult &f, const Vector &b, Vector &x)
Solve .
QRResult qr(const Matrix &A, Backend backend=lapack_backend)
Factor as .
This computes the minimizer of (|Ax-b|_2).
Tridiagonal and Banded Systems
void thomas(const Vector &a, const Vector &b, const Vector &c, const Vector &d, Vector &x, Backend backend=lapack_backend)
For general banded storage:
A(i, i) = 2.0;
if (i > 0) A(i, i - 1) = -1.0;
if (i + 1 < n) A(i, i + 1) = -1.0;
}
LAPACK-style band storage.
BandedSolverResult banded_solve(const BandedMatrix &A, const Vector &b, Vector &x)
Factor and solve .
Sparse Krylov Solve
std::vector<num::idx> rows, cols;
std::vector<num::real> vals;
rows.push_back(i);
cols.push_back(j);
vals.push_back(v);
};
push(i, i, 2.0);
if (i > 0) push(i, i - 1, -1.0);
if (i + 1 < n) push(i, i + 1, -1.0);
}
Sparse matrix in Compressed Sparse Row (CSR) format.
static SparseMatrix from_triplets(idx n_rows, idx n_cols, const std::vector< idx > &rows, const std::vector< idx > &cols, const std::vector< real > &vals)
Build from coordinate (COO / triplet) lists.
SPDOp< Op > assume_spd(Op op)
SolverResult cg(const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
Adapt a SparseMatrix to the operator protocol.
Use gmres(Aop, b, x, tol, max_iter, restart) for nonsymmetric systems.
The unified solve(problem, algorithm) form keeps the method choice explicit:
ODEResult solve(const P &prob, const RK45 &alg, ObserverFn obs=nullptr)
Linear system A x = b. A is any matrix or LinearOperator; b the RHS. Non-owning view over A and b (bi...
Result of a linear solve: the solution vector plus convergence stats.
r.u is the solution vector; r.iterations, r.residual, and r.converged report progress.
Use PCG when a preconditioner is available:
JacobiPreconditioner jacobi_preconditioner(const Matrix &A)
SolverResult pcg(const Op &A, const M &M_op, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
Use MINRES for symmetric indefinite operators:
SymmetricOp< Op > assume_symmetric(Op op)
SolverResult minres(const Op &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
Eigenvalues and SVD
SVDResult svd_truncated(const Matrix &A, idx k, Backend backend=default_backend, idx oversampling=10, Rng *rng=nullptr)
LanczosResult lanczos(const Op &A, idx k, real tol=1e-10, idx max_steps=0, Backend backend=Backend::seq)
Operator Lanczos for a declared symmetric adapter.
SVDResult svd(const Matrix &A, Backend backend=lapack_backend, real tol=1e-12, idx max_sweeps=100)
PowerResult power_iteration(const Matrix &A, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
Power iteration – finds the eigenvalue largest in absolute value.
EigenResult eig_sym(const Matrix &A, real tol=1e-12, idx max_sweeps=100, Backend backend=lapack_backend)
Adapt a dense Matrix to the operator protocol.
eig_sym returns a dense symmetric eigendecomposition. lanczos returns a small set of Ritz pairs from a dense, sparse, or matrix-free symmetric operator.
Matrix Exponential Action
Vector expv(real t, const Op &A, const Vector &v, int m_max=30, real tol=1e-8)
Compute for any adapter.
This forms \(\exp(tA)v\) by Arnoldi projection without forming \(\exp(A)\).