Back

Linear System: Direct vs Iterative

What you are seeing: the discrete 1D Poisson problem u=sin(πx)-u'' = \sin(\pi x) on NN grid points. The same right-hand side is fed to a Thomas direct solver (exact, O(N)O(N)), Jacobi, Gauss-Seidel, and conjugate gradient. The lower panel tracks the residual norm vs iteration count; CG converges in at most NN steps in exact arithmetic.

Figure 1. Solution and residual history for four solvers on u=f-u'' = f.
N (grid)32
solver

WHAT TO TRY

  • Switch the iterative solver between Jacobi, Gauss-Seidel and conjugate gradient: each drives the residual down at a different rate, and the log-residual plot shows conjugate gradient winning by far.
  • Raise the grid size N: the iterative methods slow down (their iteration count grows with N) while the Thomas direct solver stays exact in O(N). That scaling is why solver choice matters.
  • Watch the solution converge toward the exact parabola: the iterate creeps up from below as the residual shrinks, the visible meaning of an iterative method homing in on the answer.