8 | Numerical Calculus: Integration

In this section, we focus on finding integrals using numerical techniques. We will look at operating on functions and on discrete empirical data.

At the end of this section you should be able to:

  1. Employ numerical quadrature to integrate a function of one or several variables

  2. Employ trapezoidal integration to integrate empirical data of a single variable

  3. Employ Monte Carlo Integration (MCI) to integrate a function of one or several variables

  4. Identify when MCI may be a more effective technique than quadrature to integrate a function

Integration of Functions

Numerical Integration of Analytic Functions: using Matlab’s built-in numeric quadrature functions to solve functions of one, two or three variables.

Numerical Integration of Analytic Functions Example 1: here we calculate the definite integral of a function of one variable using integral.

Numerical Integration of Analytic Function Example 2: here we find the integral as a function of time of a function of one variable.

Numerical Integration of Analytic Function Example 3: here we find the volume under a surface of a function of two variables using integral2.

Integration of Data

Numerical Integration of Empirical Data: using Matlab’s built-in trapezoidal integration functions (trapz and cumtrapz) to integrate discrete data when the relationship between the independent and dependent variables is not known as a function.

Numerical Integration of Analytic Function Data Example: we revisit example 1 and use trapz to calculate the integral.

Numerical Integration of Analytic Function Data Example 4: given empirical acceleration data, we integrate it and apply an initial condition to estimate the velocity.

Monte Carlo Integration

Monte Carlo Integration: Using MCI to estimate the integral of a function when the relationship between independent and dependent variables is explicitly known. We first estimate the average value of the function by sampling it with random numbers (from a uniform distribution). We multiply this estimate by the length/area over which the line/surface acts to find the integral.

Monte Carlo Integration Example 5: we revisit example 1 again but solving the integral using MCI. We check for convergence of the result to assure that we have used enough samples in the estimate.

Monte Carlo Integration Example 6: we compute a double integral under a surface to find the volume. Again, we check for convergence of the solution to verify we used enough samples.

Lecture Code