Companion Website

Computational Physics

From Equations to Simulation

Chapter 10

Boundary Value Problems for Ordinary Differential Equations

These programs solve boundary value problems with shooting and finite differences, and find eigenvalues with Numerov shooting and a matrix method. Each program is available in MATLAB, Python, C++, and Fortran. Problem data and equations are easy to change. All programs print and save solution data; MATLAB and Python also plot the results.

The supplied examples include analytic comparisons to check the results. When changing a problem, replace or disable the exact-solution comparison and check accuracy by refining the grid or tightening tolerances. The Chapter 10 resources provide benchmarks and guidance on choosing a method.

ProgramMATLABPythonC++Fortran
0. Shooting for a second-order ODEFinds the unknown initial slope with secant iteration; each trial uses adaptive Fehlberg RKF45. The example y″ = y has an analytic solution.DownloadDownloadDownloadDownload
1. Linear finite differencesDiscretizes y″ + p(x)y′ + q(x)y = r(x) with fixed endpoint values and solves the interior tridiagonal system with the Thomas algorithm.DownloadDownloadDownloadDownload
2. Boundary-condition choicesSolves a rod-conduction example with fixed values, a derivative at either end, or a right Robin condition. The other endpoint value is fixed when using a derivative or Robin condition.DownloadDownloadDownloadDownload
3. Nonlinear finite differencesSolves y″ = f(x,y,y′) by Newton iteration; analytic partial derivatives form each tridiagonal correction system. A manufactured exact solution checks accuracy.DownloadDownloadDownloadDownload
4. Eigenvalues by Numerov shootingScans endpoint sign changes, refines each eigenvalue with bisection, and normalizes the modes of a uniform string. Uses zero-value boundaries at both ends and no first-derivative term.DownloadDownloadDownloadDownload
5. Schrödinger matrix eigenvaluesBuilds the interior finite-difference Hamiltonian and uses symmetric Jacobi rotations. Outputs the lowest energies and normalized wavefunctions for a harmonic oscillator. Edit V(x) to study another potential.DownloadDownloadDownloadDownload

← Back to Chapter 10