Main Content

Numerical Integration and Differentiation

Quadratures, double and triple integrals, and multidimensional derivatives

Numerical integration functions can approximate the value of an integral whether or not the functional expression is known:

  • When you know how to evaluate the function, you can use integral to calculate integrals with specified bounds.

  • To integrate an array of data where the underlying equation is unknown, you can use trapz, which performs trapezoidal integration using the data points to form a series of trapezoids with easily computed areas.

For differentiation, you can differentiate an array of data using gradient, which uses a finite difference formula to calculate numerical derivatives. To calculate derivatives of functional expressions, you must use the Symbolic Math Toolbox™ .


expand all

integralNumerical integration
integral2Numerically evaluate double integral
integral3Numerically evaluate triple integral
quadgkNumerically evaluate integral — Gauss-Kronrod quadrature
quad2dNumerically evaluate double integral — tiled method
cumtrapzCumulative trapezoidal numerical integration
trapzTrapezoidal numerical integration
del2Discrete Laplacian
diffDifferences and approximate derivatives
gradientNumerical gradient
polyintPolynomial integration
polyderPolynomial differentiation


Integration to Find Arc Length

This example shows how to parametrize a curve and compute the arc length using integral.

Complex Line Integrals

This example shows how to calculate complex line integrals using the 'Waypoints' option of the integral function.

Singularity on Interior of Integration Domain

This example shows how to split the integration domain to place a singularity on the boundary.

Analytic Solution to Integral of Polynomial

This example shows how to use the polyint function to integrate polynomial expressions analytically.

Integration of Numeric Data

This example shows how to integrate a set of discrete velocity data numerically to approximate the distance traveled.

Calculate Tangent Plane to Surface

This example shows how to approximate gradients of a function by finite differences.