Trapezoidal Rule: A Method of Numerical Integration
By: Kazi Abu Rousan
Tags: Science, Integration, Numerical Analysis, Mathematics, Math

Using a simple trapezoid we can solve integrations (best part is we can even let computers use this method and with some restrictions, we can also some some of the usually unsolved integrations) numerically with a desired level of accuracy.

Why Trapezoid for Integration?

We know that if we plot a given function its integration is equal to the area closed by the function’s curve with the independent variable axis.

Fig-1: Our function f(x) plotted in the coordinate plane with horizontal axis as x axis

Suppose we have a function f(x) and x is the independent variable. Let’s plot our function. After plotting f(x) vs x, if we take two points like x = a and x = b . Then, what is the value of the integration between in the limit of a and b ?

Fig-2: First pointer is at x= a and 2nd one is x=b. The pointer takes on all values of x as it goes.

As you can see, I have taken a two random point on x axis(x=a and x = b), corresponding to those x values we will get two y-values ,which are y = f(a) and y = f(b). We will get the y values for all x values between the linear region. Now what we can do is draw rectangles using consecutive points on x axis and points on the graph (As we do to define the integrations itself).

Usually we use rectangular boxes to approximate area under the curve (making width of each rectangle = dx as small as possible to get result as accurate as possible) which works fine . But in this case we’ve to use many terms(rectangles) which is not that efficient. .

Fig-3: Left side represent area approximation using rectangle and Right side shows the area approximation using trapezoid (here a = 0)

As you can see, I’ve used same number of rectangles and trapezoids in both cases with same width . Now it’s clear that trapezoids approximates the area better than rectangles which is the main idea behind using Trapezoids instead of Rectangles.

Calculating Area

Suppose we have a function f(x) and we are interested in the integration in the linear range of x = a and x = b. Then the value of integration is:

See figure 2

We have divide the x axis uniformly into small lengths ,each having a width of h = (b-a)/n . Here n(no. of trapezoid) is a huge number. The larger n will give us better result.

As the length is equally divided into n equal parts , hence we can write any point on x axis as

Remember we have created n equal lengths that means we have n + 1 points. As an example see your hands. You have 5 fingers(If you have 6 then error🤣) but It contains only 4 gaps.

Corresponding to each of those x values , If we draw lines parallel to y axis , then the points at which they intersect the curve are the corresponding function values and hence the length of each dotted lines.

Hence each purple dot on the red graph represent (x_r,f(x_r)) and here x_0 = a is used.

Fig-4: Here h = 2 unit. As you can see when we move along the arrows from 1st x to 2nd x, we add a h.

You may ask why x_r has such a value ? You can see in the figure-4, As we move from x_0=a to the end of the first trapezoid, we add it’s width to our x value. Hence, each time we cross a trapezoid , we have to add a h with the a. So, to reach the r-th point on x axis(r-th x value) we have to add h , r-times with our x_0.

As you can see each shape is a trapezoid. Hence we just need to find the area of each trapezoid and adding them will give us total area under the curve.

Fig-5: r-th trapezoid of the area approximation, which parallel sides of length f(x_r) and f(x_(r+1))

Now you see we take two point x_r and x_(r+1). For those two points we have two lines parallel two y axis, whose lengths are f(x_r) and f(x_(r+1)) . You can see clearly it is indeed a trapezoid with a height of h(x_(r+1)-x_r) and the length of 2 parallel sides are the length of the lines which are parallel to y axis. Using just normal geometric area formula of trapezoid, we get,