Companion Website

Computational Physics

From Equations to Simulation

Chapter 11

Solving Nonlinear Equations

These programs find one root with bisection, false position, Newton’s method, or the secant method, and find several distinct roots by scanning an interval and refining sign-change brackets. Each program is available in MATLAB, Python, C++, and Fortran. Choose a search interval or starting guesses from the physical problem, then check the reported residual and whether the result lies in the expected physical range.

Bisection and interval scanning stop when the bracket is sufficiently narrow; false position, Newton’s method, and the secant method use a residual tolerance. The book’s interval-scanning example refines brackets with false position; this companion program uses bisection, so its iteration counts and final estimates can differ. A scan can miss roots that do not change sign or closely spaced roots within one subinterval. The Chapter 11 resources provide benchmarks and guidance on choosing a method.

Program MATLAB Python C++ Fortran
Bisection Finds one root in a sign-change bracket by repeatedly halving it. Download Download Download Download
False position Refines one sign-change bracket using the zero of a secant line while retaining a bracket. Download Download Download Download
Newton’s method Finds one root from an initial guess using the function and its analytic derivative. Download Download Download Download
Secant method Finds one root from two initial guesses without evaluating a derivative. Download Download Download Download
Several roots by interval scanning Scans an interval for sign changes and uses bisection to refine each detected root. Download Download Download Download

← Back to Chapter 11