- Home
- Library
- Computational Quantum Field Theory
- Solving Boundary and Evolution Equations
- Finite Differences and Sparse Linear Systems
Finite Differences and Sparse Linear Systems
A field equation can have a beautifully small numerical residual and still describe the wrong continuum field. The residual tests the equations on a chosen grid; it does not test the grid itself. We will solve a sourced massive scalar problem, refine its grid, and then deliberately change the linear-solver tolerance to separate these two questions.
Preparation: Taylor expansion, matrix eigenvalues and the static limit of the Klein–Gordon equation. All lengths and fields in the numerical example are dimensionless.
A scalar field with known boundary values
Consider a real scalar in a prescribed, positive mass background,
This follows from the mostly-minus equation for a time-independent field. The background is fixed; we are solving a classical linear equation, not evaluating quantum fluctuations.
Choose a manufactured solution
Differentiating it gives the required source:
Manufacturing a source is useful because it supplies a continuum answer independently of the numerical solver. It does not prove that a method will resolve every sharply varying field. Here it lets us measure precisely what refinement changes.
Let , with and the interior points. Taylor expansion gives
The discretized operator therefore has entries
The first equation contains , which moves to the right-hand side as ; the last receives . These signs are part of the problem, not optional solver settings.
An equivalent formulation is better for interpreting relative residuals. Lift the boundary values with
Since , solve
The source remains of ordinary size as decreases. In the unlifted system the boundary entries grow like , so a tolerance measured relative to that right-hand side can obscure the accuracy needed in the interior.
Sparse structure and positive definiteness
For a vector extended by zero to both endpoints,
unless . Thus is symmetric positive definite. This fact establishes uniqueness of the discrete solution and permits conjugate gradients.
Only entries are nonzero. Matrix-vector multiplication and a tridiagonal factorization require work and storage here. A dense inverse would discard the main advantage of this one-dimensional problem. For the example, a sparse direct solve supplies a convenient reference on each grid. In several dimensions, sparse factorization can introduce substantial fill-in; that is one reason iterative methods and elliptic preconditioners become important.
The condition number also matters. The Dirichlet difference Laplacian has eigenvalues
Its smallest eigenvalue stays finite, while the largest grows like . Adding a bounded positive preserves this scaling. Refining the grid makes the approximation more accurate but the unpreconditioned system more ill-conditioned.
Conjugate gradients and an actual preconditioner
Conjugate gradients minimize the quadratic
over successive Krylov subspaces. With and search direction , the unpreconditioned recurrence is
Start with . In exact arithmetic the directions are -orthogonal, and at most steps suffice. Finite precision changes that statement. The residual norm need not decrease monotonically even when the quadratic error improves. These distinctions already appear in Hestenes and Stiefel, §§2–3, pp. 410–411 (PDF).
Use the positive definite approximation
Preconditioned CG computes , starts with , and replaces the two residual squared norms in the recurrence by . It applies through one reused tridiagonal factorization. It does not explicitly form an inverse.
The relevant symmetric operator is . From ,
The upper bound approaches as the mesh is refined. The actual generalized condition number at is . This is a substantive change from the growth of the original system. A scalar rescaling of would not change its condition number.
What the retained calculation shows
The companion finite_difference.py uses NumPy 2.0.2 and SciPy 1.13.1. Every iterative solve starts from zero, uses atol=0 and a limit of iterations. The documented CG criterion is a residual tolerance, not a bound on continuum error.
The table uses requested relative tolerance . The field error is from the sparse direct solution, in .
| Interior points | Field error | CG steps | PCG steps | |
|---|---|---|---|---|
The full scan includes as well. Halving reduces the field error by approximately four, as expected from the centered stencil. PCG needs ten matrix-vector products and ten preconditioner applications at each listed size; ordinary CG needs matrix-vector products in these runs.
The same manufactured scalar problem separates grid error from iterative work. The left panel uses direct solutions on each mesh; the right compares CG and the stated tridiagonal preconditioner at requested relative residual . The retained output also records independently recomputed residuals, including finite-precision stopping discrepancies.
There is an instructive discrepancy at the finest meshes. SciPy returns successful status, but recomputing gives relative residuals at and at for ordinary CG. The recursively updated residual and a newly computed residual have reached different rounding floors. These results are retained rather than described as satisfying the requested tolerance exactly. At , the CG solution still differs from the direct solution by only in the weighted norm.
Residual, conditioning and discretization error
Let be the exact solution of the discrete system and an iterative approximation. For the recomputed residual ,
The full error splits as
The first term is algebraic; the second is the grid error. At , PCG with requested tolerance takes five steps and has algebraic error , larger than the grid error. At it takes seven steps and the algebraic error falls to . Ten steps at reduce it to . Solving much more accurately than the discretization needs is sometimes useful for diagnostics, but it does not improve the continuum approximation.
The companion also checks the cubic-polynomial stencil, symmetry, the generalized preconditioned spectrum, the residual bound, and agreement between lifted and directly inserted boundaries. Refinement is essential even after all of these checks pass. The spectral comparison changes the discretization while preserving a boundary-value problem.
Summary
Finite differences turn local field equations into sparse systems whose boundaries, positivity and conditioning can be derived before solving. A manufactured solution measures grid error; a direct solution on the same grid measures iterative error. The useful stopping target depends on both, and an independently recomputed residual is more informative than a success flag alone.
Exercises
1. The sign of the truncation defect
For the manufactured field above, derive the first and last unlifted equations. Then calculate the leading defect and explain why a positive definite matrix does not force the defect itself to be positive.
Solution
The first row is
The last has on the right. The lift reproduces these values and its centered second derivative vanishes exactly, so both formulations are algebraically equivalent.
Since ,
The minus sign comes from the negative second derivative in the field operator. Positive definiteness asserts for a nonzero vector; it says nothing about the sign of each component of for an arbitrary trial field. Solving converts the consistency defect into field error through the inverse operator.
2. A stopping rule with a stated meaning
Suppose the desired algebraic error is at most in . Give a sufficient residual threshold using a known lower bound on . Derive the preconditioner bound above, and explain why a nonzero mesh error remains after this threshold is reached.
Solution
The spectral decomposition of the symmetric positive matrix gives . The weighted norm differs by the constant factor , so the same operator bound applies. It is sufficient to require
For this problem one may use
For any nonzero ,
These generalized Rayleigh quotients bound the spectrum of . Its condition number is therefore at most the stated upper endpoint. The residual test concerns only. Even a zero residual leaves , which the mesh scan measures as an effect.
References
- M. R. Hestenes and E. Stiefel, “Methods of Conjugate Gradients for Solving Linear Systems,” Journal of Research of the National Bureau of Standards 49 (1952), 409–436, DOI: 10.6028/jres.049.044. Consulted §§2–3, pp. 410–411, especially Eqs. (3:1)–(3:3), in the NIST copy (PDF).
- SciPy community,
scipy.sparse.linalg.cg, SciPy 1.13.1 manual: positive definiteness, inverse-preconditioner interface, residual tolerance and status.
Scrollable formula. Use Left and Right arrow keys to reveal hidden content.
Scrollable table. Use Left and Right arrow keys to reveal hidden columns.
Scrollable figure. Use Left and Right arrow keys to reveal hidden content.