Skip to main content
Interactive 3D/Conjugate Gradient
Condition Number κ
κ = 5aspect ratio
1 (sphere)50 (needle)
Show
GD Steps
20 steps
Start Point
x₀ = -2.5
y₀ = 2.5
Performance
CG steps:2
GD steps:20
CG final ‖err‖:6.50e-16
GD final ‖err‖:2.79e-3
CG (indigo) reaches exact minimum in 2 steps for 2D. GD (amber) zigzags - worse with high κ. CG uses conjugate search directions: each step is A-orthogonal to all previous.
Try κ=50: GD spirals forever. CG still takes exactly 2 steps. This is why CG is used to solve large sparse linear systems in ML (e.g. second-order optimizers).

Conjugate Gradient - Interactive Visualization

Conjugate gradient solves Ax=b (or equivalently minimizes a quadratic) in at most n steps for an n-dimensional problem. The key insight: CG search directions are conjugate (A-orthogonal) - each step corrects only what previous steps left uncorrected, without undoing prior progress. This is why CG needs only 2 steps for 2D, while steepest descent zigzags indefinitely.

  • Watch CG reach minimum in exactly 2 steps on a 2D quadratic
  • Watch steepest descent zigzag along the same problem
  • Adjust condition number κ to see how CG convergence degrades
  • See both paths animated simultaneously on elliptical contours
  • Foundation for solving large sparse linear systems in scientific computing and ML

Part of the EngineersOfAI Interactive 3D - free interactive visualizations covering every major concept in machine learning and AI engineering. Hover any element for a plain-English explanation. No code required.