Description
Implement Conjugate Gradient (CG) to solve symmetric positive-definite (SPD)
linear systems A x = b without explicit factorization.
- Scope:
src/krylov/conjugate_gradient.rs
- Signature:
conjugate_gradient<T>(A: &SymmetricMatrix<T>, b: &Vector<T>, x0: &Vector<T>, max_iter: usize, tol: T) -> Result<Vector<T>, ConvergenceError>
Implementation notes
- Convergence rate depends on
sqrt(κ(A)) — pair with high-condition-number matrices in
tests to show graceful degradation.
- Only 4 fixed-size vectors (
r, p, Ap, x), zero basis growth — stack-safe, no
const-generic basis decision needed for this one.
- Don't try to prove SPD upfront (no cheap general test) — detect operationally (negative/
~zero p·Ap mid-iteration) and fail fast.
max_iter is a mandatory hard cap, not optional.
Tasks
Tests
Description
Implement Conjugate Gradient (CG) to solve symmetric positive-definite (SPD)
linear systems
A x = bwithout explicit factorization.src/krylov/conjugate_gradient.rsconjugate_gradient<T>(A: &SymmetricMatrix<T>, b: &Vector<T>, x0: &Vector<T>, max_iter: usize, tol: T) -> Result<Vector<T>, ConvergenceError>Implementation notes
sqrt(κ(A))— pair with high-condition-number matrices intests to show graceful degradation.
r,p,Ap,x), zero basis growth — stack-safe, noconst-generic basis decision needed for this one.
~zero
p·Apmid-iteration) and fail fast.max_iteris a mandatory hard cap, not optional.Tasks
conjugate_gradient<T>(...)Err, never panicA.rows == A.cols == b.len() == x0.len())# ExamplesTests
‖b - A x‖is smallErr, not NaN/panic