6 Numerical Integration

Numerical Methods · Unit 6

Numerical Integration

Exam-focused notes for Numerical Integration (Numerical Methods, BIT203): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.

Numerical Integration in short

Some integrals have no simple antiderivative, and some functions are known only as tables. Numerical integration finds the area under a curve by adding the areas of simple shapes.

Numerical Integration: notes

Trapezoidal rule and composite trapezoidal rule

Numerical integration is required when the integrand has no closed form integral, such as $e^{-x^2}$, or when only measured data are given.

Single trapezoidal rule. Replace the curve between $a$ and $b$ by a straight line. The area is that of a trapezoid.

$$I = \int_a^b f(x),dx \approx \frac{b-a}{2}\left[f(a) + f(b)\right]$$

Composite trapezoidal rule. Divide $[a, b]$ into $n$ equal segments of width $h = (b-a)/n$. Apply the rule on each segment and add.

$$I \approx \frac{h}{2}\left[f(x_0) + 2\left(f(x_1) + f(x_2) + \cdots + f(x_{n-1})\right) + f(x_n)\right]$$

The error is $O(h^2)$. Doubling $n$ cuts the error by about four.

Example 1. Evaluate $I = \int_{-1}^{1} e^x,dx$ with $n = 4$. Then $h = 0.5$.

$x$-1-0.500.51
$e^x$0.367880.6065311.648722.71828

$$\begin{aligned} I &\approx \frac{0.5}{2}\left[0.36788 + 2(0.60653 + 1 + 1.64872) + 2.71828\right] \ &= 0.25\left[3.08616 + 6.51050\right] \ &= 2.3992 \end{aligned}$$

The exact value is $e - e^{-1} = 2.3504$.

Example 2. Evaluate $\int_2^8 (x+3)^2,dx$ with 2 and 4 segments. The exact value is $402$.

$$\begin{aligned} n = 2,\ h = 3: \quad I &= \frac{3}{2}\left[25 + 2(64) + 121\right] = 411 \ n = 4,\ h = 1.5: \quad I &= \frac{1.5}{2}\left[25 + 2(42.25 + 64 + 90.25) + 121\right] = 404.25 \end{aligned}$$

More segments give a value closer to $402$.

What this unit covers

  • Trapezoidal rule and composite trapezoidal rule
  • Simpson's 1/3 rule and composite Simpson's 1/3 rule
  • Simpson's 3/8 rule and composite Simpson's 3/8 rule
  • Double integration using Simpson's rules
  • Applications of numerical integration
  • Algorithm and program for numerical integration

Simpson's 1/3 rule and composite Simpson's 1/3 rule

2082 · 5 marks

Integrate $\int_{0}^{3} (2x^3 + 1) dx$ using Simpson's $\frac{1}{3}$ rule with $n=6$. [5]

Show solved answer

Simpson's 1/3 Rule: $\int_0^3 (2x^3 + 1),dx$ with $n = 6$

Given

  • $f(x) = 2x^3 + 1$
  • Limits: $a = 0$, $b = 3$
  • Number of intervals: $n = 6$

Step 2: Step Size

$$h = \frac{b-a}{n} = \frac{3-0}{6} = 0.5$$

Step 3: Function Values

$i$$x_i$$f(x_i) = 2x_i^3 + 1$CoeffProduct
00.0$2(0)+1 = 1.000$11.000
10.5$2(0.125)+1 = 1.250$45.000
21.0$2(1)+1 = 3.000$26.000
31.5$2(3.375)+1 = 7.750$431.000
42.0$2(8)+1 = 17.000$234.000
52.5$2(15.625)+1 = 32.250$4129.000
63.0$2(27)+1 = 55.000$155.000

Step 4: Apply the Formula

$$\int_a^b f(x),dx \approx \frac{h}{3}\Big[f_0 + f_6 + 4(f_1+f_3+f_5) + 2(f_2+f_4)\Big]$$

Compute the grouped sums:

  • End terms: $1.000 + 55.000 = 56.000$
  • Odd terms: $4(1.250 + 7.750 + 32.250) = 4(41.250) = 165.000$
  • Even terms: $2(3.000 + 17.000) = 2(20.000) = 40.000$

Total sum: $$S = 56.000 + 165.000 + 40.000 = 261.000$$

Step 5: Final Result

$$\int_0^3 (2x^3+1),dx \approx \frac{0.5}{3}(261) = \frac{261}{6} = 43.5$$

$$\boxed{\int_0^3 (2x^3+1),dx \approx 43.5}$$

Verification (Exact Value)

$$\int_0^3 (2x^3+1),dx = \left[\frac{x^4}{2} + x\right]_0^3 = \frac{81}{2} + 3 = 40.5 + 3 = 43.5$$

Simpson's 1/3 rule gives the exact answer because the integrand is a cubic polynomial (degree $\le 3$), for which the rule is exact.

Open this answer on its own page →

Double integration using Simpson's rules

2080 · 5 marks

Solve the double integration using Simpson's 1/3 rule. $$\int_{2}^{2.6} \int_{4}^{4.4} \frac{dxdy}{xy}$$ [5]

$$I = \int{2}^{2.6} \int{4}^{4.4} \frac{dx,dy}{xy}$$ - Inner variable $x$: limits $4$ to $4.4$ - Outer variable $y$: limits $2$ to $2.6$ - Integrand: $f(x,y) = \dfrac{1}{xy}$ Using $n = 2$ subintervals in each direction: - $h = \dfrac{4.4 - 4}{2} = 0.2$, giving $x0=4.0,\ x1=4.2,\ x2=4.4$ -

Open this answer on its own page →

Trapezoidal rule and composite trapezoidal rule

2080 · 5 marks

Why Numerical Integration is required? Compute the integral: $I=\int_{-1}^{1} e^x dx$ using composite trapezoidal rule for n = 4. [5]

Numerical integration (numerical quadrature) is required because: 1. No closed-form antiderivative exists for many functions such as $e^{-x^2}$ or $\frac{\sin x}{x}$. 2. The function is known only at discrete points (tabulated/experimental data), with no explicit formula available. 3. Analytical ...

Open this answer on its own page →

2078 · 5 marks

Solve the following integral using trapezoidal rule form = 8, $l=\int_{2}^{4} (x^4 + 1)dx$. [5]

  • Integral: $l = \int2^4 (x^4 + 1),dx$ - $a = 2$, $b = 4$ - Number of subintervals: $n = 8$ Step size: $$h = \frac{b-a}{n} = \frac{4-2}{8} = 0.25$$ Table of values with $f(x) = x^4 + 1$: $i$ $xi$ $xi^4$ $f(xi)$ ------------------------------- 0 2.00 16.0000 17.0000 1 2.25 25.62891 26.62891 2 2.5...
Open this answer on its own page →

0 · 5 marks

Find following integral using composite trapezoidal rule using 2 segments (k=2) and 4 segments (k=4). $$\int_{2}^{8} (x+3)^2 dx$$ [5]

Integral: $\displaystyle\int2^8 (x+3)^2,dx$ - Lower limit: $a = 2$ - Upper limit: $b = 8$ - Integrand: $f(x) = (x+3)^2$ - Cases: $k = 2$ segments and $k = 4$ segments $$\inta^b f(x),dx \approx \frac{h}{2}\left[f(x0) + 2\sum{i=1}^{k-1}f(xi) + f(xk)\right], \quad h = \frac{b-a}{k}$$ $$\int2^8 (x+...

Open this answer on its own page →

Algorithm and program for numerical integration

2079 · 10 marks

What do you mean by numerical integration? Write any one application of numerical integration. Write an algorithm and c program to implement multi-segment trapezoidal rule.[10]

Show solved answer

Numerical Integration: Multi-Segment Trapezoidal Rule


1. What is Numerical Integration? (2 marks)

Numerical Integration (also called numerical quadrature) is the process of computing the approximate value of a definite integral using numerical methods when:

  • The integrand f(x) is too complex to integrate analytically, or
  • The function is given only as a set of discrete data points (tabular data), or
  • The antiderivative does not exist in closed form.

The general goal is to approximate:

$$I = \int_a^b f(x), dx$$

by replacing the integrand with a simpler approximating function (such as polynomials) and summing the areas of geometric shapes under the curve.


2. Application of Numerical Integration (1 mark)

Engineering Application: Computing the area under a velocity-time curve to find displacement, or calculating the work done by a variable force:

$$W = \int_{x_1}^{x_2} F(x), dx$$

where F(x) may be given only as experimental data points, making analytical integration impossible.


3. Multi-Segment Trapezoidal Rule (7 marks)

Concept

The interval [a, b] is divided into n equal sub-intervals (segments), each of width:

$$h = \frac{b - a}{n}$$

The nodes are: $x_0 = a,; x_1 = a+h,; x_2 = a+2h,; \ldots,; x_n = b$

Each sub-interval is approximated by a trapezoid. The formula is:

$$\boxed{I \approx \frac{h}{2}\left[f(x_0) + 2f(x_1) + 2f(x_2) + \cdots + 2f(x_{n-1}) + f(x_n)\right]}$$

Or equivalently:

$$I \approx \frac{h}{2}\left[f(x_0) + f(x_n) + 2\sum_{i=1}^{n-1} f(x_i)\right]$$


Algorithm

Algorithm: Multi-Segment Trapezoidal Rule
Input : a (lower limit), b (upper limit), n (number of segments)
Output: Approximate value of integral I

Step 1: START
Step 2: Read a, b, n
Step 3: Compute h = (b - a) / n
Step 4: Set sum = f(a) + f(b)          [first and last terms]
Step 5: Set i = 1
Step 6: WHILE i <= n-1 DO
            x = a + i * h
            sum = sum + 2 * f(x)       [middle terms multiplied by 2]
            i = i + 1
        END WHILE
Step 7: I = (h / 2) * sum
Step 8: Print I
Step 9: STOP

C Program

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

/* Define the function to be integrated */
/* Example: f(x) = x^2, change as needed */
double f(double x) {
    return x * x;   /* Replace with desired function */
}

int main() {
    double a, b, h, sum, x, result;
    int n, i;

    /* Input */
    printf("Enter lower limit (a): ");
    scanf("%lf", &a);

    printf("Enter upper limit (b): ");
    scanf("%lf", &b);

    printf("Enter number of segments (n): ");
    scanf("%d", &n);

    /* Step size */
    h = (b - a) / n;

    /* Apply Multi-Segment Trapezoidal Rule */
    /* First and last terms */
    sum = f(a) + f(b);

    /* Middle terms */
    for (i = 1; i <= n - 1; i++) {
        x = a + i * h;
        sum = sum + 2 * f(x);
    }

    /* Final result */
    result = (h / 2) * sum;

    printf("\nApproximate value of integral = %.6lf\n", result);

    return 0;
}

Sample Output

For $\int_0^1 x^2, dx$ with n = 4:

ix_if(x_i) = x_i^2
00.000.0000
10.250.0625
20.500.2500
30.750.5625
41.001.0000

$$h = \frac{1-0}{4} = 0.25$$

$$I \approx \frac{0.25}{2}\left[0 + 1 + 2(0.0625 + 0.25 + 0.5625)\right]$$

$$I \approx 0.125 \times [1 + 2(0.875)] = 0.125 \times 2.75 = \mathbf{0.34375}$$

Exact value = 1/3 = 0.33333... (small error due to finite segments; error decreases as n increases)


Key Points

FeatureDetail
Method typeNewton-Cotes closed formula
Order of accuracyO(h^2) per segment
Error decreasesAs n increases (h decreases)
Easy to implementYes, simple loop structure
Open this answer on its own page →

Simpson's 3/8 rule and composite Simpson's 3/8 rule

2079 · 5 marks

Simpson's 3/8 Rule Integration Problem

The simple Simpson's 3/8 rule fits a single cubic polynomial over 3 sub-intervals (4 points). Its limitations: - It applies only to exactly 3 sub-intervals. A dataset with many points cannot be handled directly. - Fitting one cubic over a wide interval produces large truncation error. - The compo...

Open this answer on its own page →

2078 · 10 marks

Derive the formula for integration using simpsons 3/8 rule. Use Secant Method to estimate the root of equation with initial estimate x₁ = 4 and x₂ = 2, $x^2 - 4x - 10 = 0$. [10]

Divide $[a,b]$ into 3 equal sub-intervals with 4 points: $$x0=a,\quad x1=a+h,\quad x2=a+2h,\quad x3=a+3h=b,\qquad h=\frac{b-a}{3}$$ Let $yi=f(xi)$. Use Newton's forward interpolation with $x=x0+th$, $dx=h,dt$: $$f(x)\approx y0+t\Delta y0+\frac{t(t-1)}{2!}\Delta^2 y0+\frac{t(t-1)(t-2)}{3!}\Delta^...

Open this answer on its own page →