Numerical MethodUnit 58 min read

Numerical Integration – Quadrature, Error, and Applications

Unit 5 of Numerical Method: Covers numerical integration techniques, Newton‑Cotes formulas, composite rules, error analysis, and real‑world applications such as finance, traffic, and data analytics.

Key points

  • Numerical integration replaces analytical antiderivatives with weighted sums of function values.
  • Newton‑Cotes formulas (trapezoidal, Simpson’s 1/3, 3/8) are closed formulas derived from interpolating polynomials.
  • Composite rules increase accuracy by partitioning the interval; error decreases with higher order and smaller step size.
  • Sources of error include truncation, round‑off, and cancellation; understanding them guides method selection.
  • Applications range from computing areas under curves to estimating loan interest, average speeds, and trading volumes.

Introduction

Numerical integration, or quadrature, is the process of approximating the definite integral

when an antiderivative of is unavailable or inconvenient. The idea is to replace the integral by a weighted sum of function values at selected points.

Fundamental Concepts

Definition

A numerical integration rule has the form

where are nodes in and are weights. The rule is exact for all polynomials of degree if the weights and nodes satisfy the corresponding moment equations.

Interpolatory Quadrature

If is approximated by an interpolating polynomial that matches at the nodes , then

The integral of can be computed exactly, yielding the weights .

Error Term

For a rule exact for polynomials up to degree , the error for a sufficiently smooth is

The magnitude of the error depends on the step size and the derivative of .

Newton‑Cotes Formulas

Rule Nodes Weights Order Error Term
Trapezoidal 1
Simpson’s 1/3 3
Simpson’s 3/8 3

Figure 1 – Graph of on with nodes for the composite trapezoidal rule (n=4).

Derivation of Simpson’s 3/8 Rule

Using a cubic interpolant through four equally spaced points with spacing , the integral of the interpolant over yields the weights shown above. The derivation follows the standard Lagrange interpolation procedure and integration of each basis polynomial.

Composite Rules

Composite rules apply a basic Newton‑Cotes rule over many subintervals.

Composite Trapezoidal Rule

For subintervals of width :

Composite Simpson’s 1/3 Rule

Requires an even number of subintervals :

Composite Simpson’s 3/8 Rule

Requires divisible by 3:

Figure 2 – Composite trapezoidal rule over with .

Error Analysis of Composite Rules

For the composite trapezoidal rule:

For composite Simpson’s 1/3:

Thus, for smooth functions, Simpson’s rule converges faster (order ) than the trapezoidal rule (order ).

Worked Example – Composite Trapezoidal Rule

Compute

using the composite trapezoidal rule with .

  1. Step size .
  2. Nodes: .
  3. Function values:
  4. Apply the formula:

  5. Exact value: .
  6. Absolute error: .

Figure 3 – Error plot for composite trapezoidal rule on with .

Double Integral Example – Simpson’s 1/3 Rule

Evaluate

using Simpson’s 1/3 rule in both directions.

  1. Partition into two subintervals: .
  2. Partition into two subintervals: .
  3. Compute function values at the 9 grid points:

    (values omitted for brevity).
  4. Apply the 2‑D Simpson’s 1/3 rule:
  5. Numerical evaluation gives .

Figure 4 – Grid and weights for 2‑D Simpson’s 1/3 rule over .

Error Sources in Numerical Integration

Source Description Typical Impact
Truncation Difference between integral of and integral of interpolant Depends on rule order and step size
Round‑off Finite‑precision arithmetic in evaluating and summing Becomes significant for very small or large
Cancellation Subtraction of nearly equal numbers in weights Can amplify relative error
Function evaluation error Approximation of (e.g., via series) Adds to truncation error

Figure 5 – Bar chart of error contributions for composite Simpson’s rule on a smooth function.

Advantages and Disadvantages

Rule Advantages Disadvantages
Trapezoidal Simple, requires only two function evaluations per subinterval Low order (O(h²)), poor for highly curved functions
Simpson’s 1/3 Higher order (O(h⁴)), accurate for smooth functions Requires even number of subintervals, more evaluations
Simpson’s 3/8 Handles any number of subintervals divisible by 3 Slightly larger error constant than 1/3 rule, more evaluations

Applications

  1. Finance – Computing total interest on a loan with a time‑varying interest rate :

    Numerical integration approximates the area under the rate curve.

  2. Traffic Engineering – Estimating average travel time on a route where speed varies with distance :

  3. Data Analytics – Calculating the cumulative distribution function (CDF) of a continuous variable from its probability density function (PDF).

In the real world

  • eSewa – The mobile payment app calculates the total transaction fee for a batch of payments. The fee is a function of transaction amount . eSewa uses the composite trapezoidal rule to integrate this fee function over the range of amounts processed in a day, yielding the total fee revenue.

  • Google Maps – When a user requests a route that follows a curved road, Google Maps approximates the route length by integrating the speed profile along the path. The integral

    is evaluated numerically using Simpson’s 1/3 rule on discretized GPS points.

  • NEPSE (National Stock Exchange of Nepal) – The exchange calculates the daily trading volume index by integrating the trading volume density over the trading hours. A composite trapezoidal rule with hourly data points provides a quick estimate of the total volume.

Google Maps routeGoogle Maps route visualization (Image: OathOn, CC BY-SA 4.0, via Wikimedia Commons)

Algorithm – Composite Trapezoidal Rule (Mermaid)

flowchart TD
  "Start"["Start"] --> "Input: f, a, b, n"
  "Compute h"["h = (b-a)/n"] --> "Initialize sum = f(a)+f(b)"
  "Loop i=1 to n-1"["For i=1 to n-1"] --> "x_i = a + i*h"
  "x_i" --> "sum = sum + 2*f(x_i)"
  "sum" --> "End Loop"
  "Result"["I = (h/2)*sum"] --> "Output I"
  "Output I" --> "End"

C Program – Composite Trapezoidal Rule

#include <stdio.h>
#include <math.h>

/* Function to integrate */
double f(double x) {
    return exp(x);   /* Example: e^x */
}

/* Composite trapezoidal rule */
double trapezoidal(double (*func)(double), double a, double b, int n) {
    double h = (b - a) / n;
    double sum = func(a) + func(b);
    for (int i = 1; i < n; ++i) {
        double x = a + i * h;
        sum += 2.0 * func(x);
    }
    return (h / 2.0) * sum;
}

int main(void) {
    double a = -1.0, b = 1.0;
    int n = 4;
    double I = trapezoidal(f, a, b, n);
    printf("Approximate integral = %.6f\n", I);
    return 0;
}

Exam tip

  • Derivation questions: Show the Lagrange interpolant and integrate term‑by‑term to obtain weights.
  • Error questions: Write the error formula for the requested rule and identify the derivative that appears.
  • Worked example: Follow the step‑by‑step procedure: compute , list nodes, evaluate , apply the formula, and compute the error if the exact integral is known.
  • Algorithm questions: Sketch a flowchart or write pseudocode; emphasize initialization, loop over subintervals, and final multiplication by or .
  • Multiple‑choice: Pay attention to subtle differences between Simpson’s 1/3 and 3/8 rules (order, step size divisibility).

Based on the TU BIT syllabus for Numerical Method (BIT203), unit 5.

Discussion

Loading…