Examples#

This gallery walks through every public feature of mathematicskit.calculus: finite-difference differentiation and Richardson extrapolation, quadrature rules, forward- and reverse-mode automatic differentiation, and Taylor series.

Each script in this gallery is self-contained and can be run directly with python examples/calculus/<section>/<script>.py.

Sections#

  • exhaustion – Archimedes’ polygon bounds on pi.

  • newton_leibniz – the derivative and the integral as limits of difference quotients and sums.

  • finite_differences – Richardson extrapolation, Fermat’s adequality, and the complex-step derivative.

  • quadrature – Riemann sums, Simpson’s rule, Gauss-Legendre, Euler-Maclaurin, Romberg, Clenshaw-Curtis, tanh-sinh, and adaptive (QUADPACK) quadrature.

  • dual_numbers – forward-mode automatic differentiation with no finite-difference truncation error.

  • autodiff – reverse-mode (backpropagation-style) automatic differentiation for multivariable gradients.

  • taylor_series – Taylor’s theorem: Taylor polynomials, the Lagrange remainder bound, and radius of convergence.

Reverse-mode autodiff#

A small backpropagation-style engine for multivariable gradients.

Reverse-mode automatic differentiation for multivariable gradients

Reverse-mode automatic differentiation for multivariable gradients

Dual numbers#

Forward-mode automatic differentiation: exact derivatives with no finite-difference truncation error.

Forward-mode automatic differentiation via dual numbers

Forward-mode automatic differentiation via dual numbers

Method of exhaustion#

Archimedes’ polygon bounds on pi, the oldest convergent approximation scheme.

Archimedes’ method of exhaustion: squeezing pi

Archimedes' method of exhaustion: squeezing pi

Finite differences#

Richardson extrapolation, Fermat’s adequality, and the complex-step derivative.

Richardson extrapolation: cancelling error terms at a fixed step

Richardson extrapolation: cancelling error terms at a fixed step

Fermat’s adequality: maxima from a difference quotient

Fermat's adequality: maxima from a difference quotient

The complex-step derivative: no cancellation

The complex-step derivative: no cancellation

Newton and Leibniz#

The two central facts of the calculus of Newton and Leibniz: the derivative is a limiting difference quotient, and the definite integral is a limiting sum.

Newton and Leibniz: the derivative and the integral as limits

Newton and Leibniz: the derivative and the integral as limits

Quadrature#

Riemann sums, Simpson’s rule, Gauss-Legendre, Euler-Maclaurin, Romberg, Clenshaw-Curtis, tanh-sinh, and QUADPACK-style adaptive quadrature.

Gaussian quadrature: optimal nodes are exact to degree 2n-1

Gaussian quadrature: optimal nodes are exact to degree 2n-1

Simpson’s rule: parabolas through pairs of panels

Simpson's rule: parabolas through pairs of panels

Riemann sums: the definition of the integral

Riemann sums: the definition of the integral

Euler-Maclaurin: correcting the trapezoidal rule

Euler-Maclaurin: correcting the trapezoidal rule

Romberg integration: extrapolating the trapezoidal rule

Romberg integration: extrapolating the trapezoidal rule

Clenshaw-Curtis vs. Gauss-Legendre quadrature

Clenshaw-Curtis vs. Gauss-Legendre quadrature

Tanh-sinh quadrature: integrating endpoint singularities

Tanh-sinh quadrature: integrating endpoint singularities

Adaptive quadrature (QUADPACK): subdividing where it is needed

Adaptive quadrature (QUADPACK): subdividing where it is needed

Taylor series#

Maclaurin series for standard functions, their convergence, and their radius of convergence.

Taylor’s theorem: polynomials, remainder bound, and convergence

Taylor's theorem: polynomials, remainder bound, and convergence

Gallery generated by Sphinx-Gallery