Companion Website

Computational Physics

From Equations to Simulation

Codes

Source codes are organized by chapter and by numerical method or computational example. Where available, matching implementations are provided in MATLAB, Python, C++, and Fortran.

The same descriptive filename stem is used across programming languages whenever the implementations correspond to the same code.

Chapter 7

Numerical Integration

Program MATLAB Python C++ Fortran
Composite trapezoidal and Simpson rules Comparison of two basic composite Newton–Cotes methods on successively finer grids. DownloadDownloadDownload Download
Gauss–Legendre quadrature General n-point Gauss–Legendre integration with nodes and weights generated numerically. DownloadDownloadDownload Download
Adaptive Simpson integration Adaptive Simpson integration using non-recursive interval subdivision and an error estimate. DownloadDownload Download
Gauss–Kronrod adaptive integration (G7–K15 and G10–K21) Adaptive integration using two embedded Gauss–Kronrod quadrature pairs. DownloadDownloadDownload Download
QUANC8 adaptive integration Adaptive 8-panel Newton–Cotes integration. Download Download Download Download
Improper integral: infinite interval Maps a semi-infinite domain to a finite interval and applies Gauss–Legendre quadrature. DownloadDownloadDownload Download
Cauchy principal-value integral Analytical subtraction of a simple pole followed by Gauss–Legendre quadrature. DownloadDownloadDownload Download
Rapidly oscillating integral Comparison of composite Simpson and quadratic Filon integration for a rapidly oscillating function. DownloadDownloadDownload Download
Nested Simpson integration in two dimensions Nested one-dimensional Simpson integrations for a two-dimensional problem with a variable inner limit. DownloadDownload Download
Two-dimensional Gauss–Legendre product rule Tensor-product Gauss–Legendre quadrature for a smooth function on a rectangular domain. DownloadDownloadDownload Download

← Back to Chapter 7