Companion Website

Computational Physics

From Equations to Simulation

Resources

This page provides practical material that complements the book and the companion source codes: links to maintained numerical libraries, benchmark problems for testing, method-selection guidance, and selected references.

The companion codes are intended primarily for learning, experimentation, and situations where a numerical method is useful as a transparent component of a larger program. For general-purpose scientific computing, well-tested library routines are usually the preferred choice because they provide mature error control, extensive testing, and robust implementations.

Appendix B of the book provides a broader survey of numerical routines and scientific software. The links on this page are meant to provide convenient access to current documentation.

Chapter 7

Numerical Integration

The Chapter 7 companion programs implement the principal algorithms explicitly in MATLAB, Python, C++, and Fortran. The resources below connect those implementations with general-purpose library routines and provide reference problems for verification.

Software and library resources

The table lists typical production-quality options corresponding to the numerical tasks treated in Chapter 7. The exact capabilities and calling conventions differ between libraries, so the linked documentation should be consulted for details.

On a narrow screen, scroll horizontally to view all language columns.

Numerical task MATLAB Python C++ Fortran
General adaptive one-dimensional integration Automatic quadrature with user-controlled tolerances. integral
quadgk
scipy.integrate.quad GSL qag / qags QUADPACK DQAG / DQAGS
Infinite intervals Improper integrals with one or both limits infinite. integral
quadgk
quad with infinite bounds GSL qagi / qagiu / qagil QUADPACK DQAGI
Cauchy principal-value integrals Integrals containing a simple pole inside the interval. Analytical subtraction with integral or quadgk quad
weight='cauchy'
GSL qawc QUADPACK DQAWC
Oscillatory integrals Rapid oscillations or explicit sine/cosine kernels. quadgk or specialized oscillatory methods quad
weight='sin' or 'cos'
GSL qawo / qawf QUADPACK DQAWO / DQAWF
Fixed Gaussian quadrature Efficient high-order quadrature for smooth integrands. quadgk for adaptive Gaussian-type quadrature scipy.integrate.fixed_quad GSL fixed quadrature routines Library-specific Gaussian rules; custom Gauss–Legendre implementations are also common.
Multidimensional integration Low-dimensional nested quadrature or higher-dimensional integration. integral2
integral3
nquad, dblquad, tplquad Nested one-dimensional quadrature;
GSL VEGAS / MISER for higher dimensions.
Nested QUADPACK calls for low dimensions;
specialized or Monte Carlo methods for higher dimensions.

Benchmark integrals and reference values

These examples are useful for checking a new implementation, comparing algorithms, or testing changes to the companion programs. Whenever possible, compare both the integral and the reported error behavior.

Test problem Reference value What it tests
0π sin(x) dx 2 Basic composite and Gaussian quadrature.
01 dx / [1 + 400(x - 0.2)2] [atan(16) + atan(4)] / 20
≈ 0.1417097590
Localized narrow peak and adaptive subdivision.
0 e-x sin(x) dx 1/2 Infinite interval and variable transformation.
PV ∫-11 cos(x)/(x - 0.2) dx ≈ -0.5912784964342436 Cauchy principal value and analytical subtraction.
01 e-x cos(50x) dx ≈ -1.6717740468665e-3 Rapid oscillation; comparison of general and oscillatory-specific methods.
0101 1/(1+x2+y2) dy dx ≈ 0.6395103518703110 Two-dimensional product Gauss–Legendre quadrature.
010sin(x) x2/(y2+2) dy dx ≈ 0.1034464976429315 Nested integration with a variable inner limit.

Choosing an integration method

Character of the problem Method to consider Practical note
Smooth function on a finite interval Gauss–Legendre or a general adaptive library routine High-order Gaussian rules can be very efficient for smooth integrands.
Automatic error control is needed Adaptive Gauss–Kronrod Use absolute and relative tolerances appropriate to the physical problem.
Localized peak or rapidly varying region Adaptive Simpson or adaptive Gauss–Kronrod Plot the integrand first; adaptive subdivision should concentrate work where needed.
Infinite interval Variable transformation or a library routine supporting infinite limits Inspect the transformed integrand as well as the original one.
Simple pole inside the interval Analytical subtraction or a dedicated principal-value routine Do not treat an interior pole as an ordinary integrand.
Rapid oscillations Filon-type, weighted, or other oscillatory-specific quadrature General adaptive methods may require many function evaluations.
Smooth integral in two dimensions Product Gaussian quadrature or adaptive multidimensional routine Tensor-product rules are effective at low dimension but scale poorly as dimension increases.
Variable multidimensional boundary Nested integration Control the accuracy of inner integrations so they do not dominate the outer error.

Selected references and documentation

← Back to Chapter 7