PhysSandbox
Classical MechanicsWaves & SoundElectricity & MagnetismOptics & LightGravity & OrbitsLabs
🌙Astronomy & The Sky🌡️Thermodynamics🌍Biophysics, Fluids & Geoscience📐Math Visualization🔧Engineering🧪Chemistry

More from Math Visualization

Other simulators in this category — or see all 84.

View category →
NewUniversity / research

Power Iteration Eigenvalue Convergence

Visualize dominant eigenvector convergence: spectral gap ratio, Rayleigh quotient, eigen residual, and normalized power iterates on the unit circle.

Launch Simulator
NewUniversity / research

Newton-Raphson Basins in 2D Systems

Map Newton basins for nonlinear F(x,y)=0 systems: initial-guess sensitivity, iteration counts, root attraction, and singular-Jacobian failures.

Launch Simulator
NewUniversity / research

Monte Carlo Integration & Variance Reduction

Compare plain Monte Carlo, importance sampling, and stratified sampling for ∫f(x)dx, with convergence curves, standard error, and the 1/√N rate.

Launch Simulator
NewUniversity / research

PCA / SVD Geometry

Covariance ellipse and SVD view of dimensionality reduction: principal components, explained variance, and rank-1 reconstruction error.

Launch Simulator
NewUniversity / research

Gradient Descent Optimizers

Compare SGD, momentum, and Adam on a curved loss landscape; tune learning rate, curvature, stability, and iteration count.

Launch Simulator
NewUniversity / research

Gaussian Mixture EM Algorithm

Expectation-maximization for a two-component Gaussian mixture: responsibilities, E/M steps, likelihood, and covariance ellipses.

Launch Simulator
PhysSandbox

Interactive physics, chemistry, and engineering simulators for students, teachers, and curious minds.

Physics

  • Classical Mechanics
  • Waves & Sound
  • Electricity & Magnetism

Science

  • Optics & Light
  • Gravity & Orbits
  • Astronomy & The Sky

More

  • Thermodynamics
  • Biophysics, Fluids & Geoscience
  • Math Visualization
  • Engineering
  • Chemistry

© 2026 PhysSandbox. Free interactive science simulators.

PrivacyTermsContact
Home/Math Visualization/Conjugate Gradient Solver

Conjugate Gradient Solver

Conjugate gradient (CG) solves symmetric positive definite systems Ax=b by minimizing the quadratic f(x)=1/2 x^T A x - b^T x. This simulator uses a 2D SPD matrix so the geometry is visible: ellipses are level sets of the quadratic, the exact solution is the ellipse center, the residual is b-Ax, and CG chooses A-conjugate search directions. The same starting point is also shown with steepest descent, making zig-zagging and condition-number effects easy to compare.

Who it's for: Numerical linear algebra, scientific computing, optimization, PDE solvers, and applied math courses.

Key terms

  • Conjugate gradient
  • SPD matrix
  • Residual norm
  • Quadratic minimization
  • Condition number
  • Steepest descent

In exact arithmetic, CG reaches the 2D solution in at most two iterations. Extra iterations here mainly show roundoff-scale residuals and how the path differs from steepest descent.

Live graphs

SPD matrix A

1
14
30°
2

Right-hand side and start

2.2
1.1
-2.2
2

Measured values

Condition number κ14.00
Residual norm ||r||0.00000
Current xk(2.132, 1.219)
Exact x*(2.132, 1.219)

How it works

Conjugate gradient visualization for a 2D symmetric positive definite system Ax=b, residual norm, and quadratic minimization geometry.

Key equations

CG solves Ax=b by minimizing f(x)=1/2 x^T A x − b^T x for SPD A
α_k=(r_k^T r_k)/(p_k^T A p_k), β_k=(r_{k+1}^T r_{k+1})/(r_k^T r_k)

Frequently asked questions

Why does CG need the matrix to be symmetric positive definite?
SPD makes the quadratic strictly convex and defines the A-inner product used for conjugate directions. Without those properties the classic CG guarantees no longer apply.
Why can CG solve a 2D system in two steps?
In exact arithmetic, CG minimizes over a growing Krylov subspace and terminates in at most n iterations for an n-dimensional SPD system. The 2D demo reaches the solution after at most two independent directions.