Skip to content

8. Numerical Integration

Bora Canbula edited this page Jan 13, 2024 · 2 revisions

The basic idea behind the numerical integration is calculating the approximate area between the curve of the function and the x-axis by using the shapes that we know how to calculate their area.

Midpoint Rule

Using rectangles to calculate the area under the function's curve is called the midpoint rule. The name arises from taking the midpoint instead of begin or end points. For integrating a function $f(x)$ from $a$ to $b$, suppose that we divide this interval to $n$ subdivision, so we can find the length of every step as $$h = \frac{b-a}{n}$$ For every step, the area of the rectangle $I_i$ which fits between the x-axis and the curve of the function is $$I_1 = f(a+\frac{1}{2}h) h ~~ , ~~ I_2 = f(a+\frac{3}{2}h) h ~~ , ~~ I_3 = f(a+\frac{5}{2}h) h ~~ , ~~ \ldots$$ Taking the sum of these areas gives us an approximation of the integral: $$\int_a^b f(x) dx = h \sum_{i=0}^{n-1} f \left( a + \left( i + \frac{1}{2} \right) h \right)$$

Trapezoidal Rule

Using trapezoids instead of rectangles is called trapezoidal rule. While the bottom of the trapezoids is on the x-axis, the top side connects the starting and the ending point of the step. The area of the trapezoids can be easily calculated as $$I_1 = f(a) h + \frac{1}{2} \left[ f(a+h) - f(a) \right] h ~~ , ~~ I_2 = f(a+h) h + \frac{1}{2} \left[ f(a+2h) - f(a+h) \right] h ~~ , ~~ \ldots$$ Taking the sum of these areas gives the general formula for the trapezoidal rule: $$\int_a^b f(x) dx = \frac{h}{2} \left[ f(a) + 2 \sum_{i=1}^{n-1} f(a+ih) + f(b) \right]$$

Simpson's Rule

A more advanced approach can be connecting the steps with polynomials instead of lines. If the sequential 3 points connected with a second-order interpolating polynomial gives the Simpson's 1/3 rule: $$\int_a^b f(x) , dx = \frac{h}{3} \left[ f(a) + 4 \sum_{i=1,3,5}^{n-1}f(a+ih) + 2 \sum_{j=2,4,6}^{n-2} f(a+jh) + f(b) \right]$$ For using this equation, the number of steps $n$ must be even.

The number of the points connected with an interpolating polynomial can be increased. For instance if we use a third-order polynomial for sequential 4 points, we get the Simpson's 3/8 rule: $$\int_a^b f(x) , dx = \frac{3h}{8} \left[ f(a) + 3 \sum_{i=1,4,7}^{n-2}\left[ f(a+ih) + f(a+(i+1)h) \right] + 2 \sum_{j=3,6,9}^{n-3} f(a+jh) + f(b) \right]$$