Trapezoidal approximation is a numerical integration technique used in scientific computing. It is a simple and relatively accurate numerical approximation of a definite integral, which is important when working with computers that can't perform symbolic integration and when there is no known integral for a function. Although there is some error associated with trapezoidal approximation, it can be negligible depending on the application. Sampling the function in question more frequently can also reduce it.

Choose a number of times (N) to sample a function in the integration interval (a, b). Unfortunately, this is more art than science. While the trapezoidal rule rarely overestimates the value of a definite integral, it can underestimate. Increasing the number of samples increases both the accuracy of the approximation and the work involved. When calculating by hand, this typically involves about 10 samples. When the calculations are performed on a computer, it generally involves hundreds or thousands.

Determine the space between samples (h) by dividing the width of the integration interval (b  a) by the number of samples you will take (N). For example, if you are sampling a function 20 times between 0 and 10, the spacing is (10  0) / 20 = 0.5.

Add the values of the function at the bounds of integration. For example, if you are integrating the function f(x) = sin(x) on the interval (0, 10), add sin(0) to sin(10).

Starting with n = 1 and continuing to n = N  1, sample the function at a + nh, where a is the left bound of the interval and h is the spacing you determined in Step 2. Add these samples and multiply the answer by two. For example, if you are sampling 20 times between 0 and 10, sample the function at 0 + 10.5, 0 + 20.5, 0 + 30.5, ..., 0 + 190.5. With the function f(x) = sin(x), this yields 2 [sin(0.5) + sin(1) + sin(1.5) + sin(2) + ... + sin(9.5)]

Add the answers you found in Steps 3 and 4, multiply by the interval spacing h, and divide this product by two. For example, if the answer for Step 3 is 0.5440, the answer from Step 4 is 7.746 and the spacing h is 0.5. Adding the answers from Steps 3 and 4 yields 7.2024. Multiplying that answer by h/2 yields a total area of 1.8006. The actual area for the function sin(x) on that interval is 1.839.
References
 Photo Credit Comstock/Comstock/Getty Images