Fourth-order finite differences and numerical linear algebra in Python
Published:

Final project for the course Applied Mathematics: an Introduction to Scientific Computing (Luca Heltai, Gianluigi Rozza, Stefano Piani, Giovanni Stabile), SISSA, 2021–2022.
The project solves the Poisson equation \(-u_{xx} = f\) on \((0, \pi)\) with a 5-point, 4th-order finite-difference stencil. On \((0, 1)\) with \(f(x) = x(1-x)\), the scheme shows 4th-order convergence: the error drops by a factor of 16 each time the grid spacing is halved, down to about \(2 \times 10^{-13}\).
All the linear algebra is written from scratch: LU and Cholesky factorizations with forward and backward substitution, the condition number and the inverse of the matrix from the LU factors, a conjugate gradient solver with an optional preconditioner, and power and inverse power iterations for the largest and smallest eigenvalues. The time-dependent problem \(u_t - u_{xx} = \cos(t) \sin(x)\) is integrated with forward Euler under its stability limit and matches the exact solution, and a backward Euler scheme with Newton’s method solves the nonlinear Cauchy problem \(y' = -t y^2\).
