The Trapezoidal Rule

The simplest methods follow from assuming that each strip under the curve is a rectangle based on the function value at the left or at the right of each strip. However, intuition tells us that this will give a very inaccurate value for the area since we are approximating the underlying function by straight line segments.

A more accurate form follows if we assume that each strip is of the shape of a trapezoid. The area of such a trapezoidal shaped strip is

\begin{displaymath}
d a_i = ( f_i + f_{i+1} ) \frac{ dx}{2}
\end{displaymath} (5)

for the strip delimited by $f_i$ and $f_{i+1}$. The area under the curve is simply the sum of the area of each strip from $A$ and $B$.
\begin{displaymath}
I = \sum_{i=0}^{i=N-2} d a_i
\end{displaymath} (6)

The method is illustrated in the code Integral.cpp. FunctionOnGrid.cpp is used to pipe data in this code.

The advantage of using the simple form of $ f(x) = x ~ \exp{ - x^2 } $ is that the exact integral is easily analytically performed


\begin{displaymath}
I = \int \exp{ - x^2 } dx = - \exp{ - x^2 }
\end{displaymath} (7)

therefore
\begin{displaymath}
I = \int_A^B f(x) dx = - ( exp{- B^2 } - \exp{ - A^2 } )
\end{displaymath} (8)

Can you derive this result?

What is the percent error in the Trapezoidal rule area as compared to the exact one?

2015-01-05