Linear System: Direct vs Iterative
What you are seeing: the discrete 1D Poisson problem on grid points. The same right-hand side is fed to a Thomas direct solver (exact, ), Jacobi, Gauss-Seidel, and conjugate gradient. The lower panel tracks the residual norm vs iteration count; CG converges in at most steps in exact arithmetic.
N (grid)32
solver
‖r‖:0
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.