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

Related simulators

Continue with similar topics in this category — or all 85 in Math Visualization.

View category →
NewSchool

Gradient Descent (2D)

Launch Simulator

Level sets of f(x,y) and path (x,y) ← (x,y) − η∇f; bowl or elliptic well.

NewUniversity / research

Finite Element Poisson Solver (2D)

Launch Simulator

Triangular P1 finite elements for -Δu=f on a square: assemble stiffness matrices, pin Dirichlet nodes or add natural Neumann flux, solve by CG, and view potential as a colored membrane.

NewUniversity / research

PCA / SVD Geometry

Launch Simulator

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

NewUniversity / research

Gradient Descent Optimizers

Launch Simulator

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

NewUniversity / research

Flow Field Particles

Launch Simulator

Synthetic v(x,y,t); advection with wrap; optional arrow grid.

NewUniversity / research

Heat Equation: Finite Differences

Launch Simulator

1D heat equation u_t = αu_xx with explicit FTCS and implicit backward Euler; tune CFL r = αΔt/Δx², watch explicit blow-up for r > 1/2, and compare numerical diffusion.

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

SPD system Ax=b as quadratic minimization: contour geometry, CG vs steepest descent path, residual norm, and condition number.

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.

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)

Live graphs

About this model

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

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.