Solaris

Trapezoidal Rule2

알 수 없는 사용자 2008. 2. 25.
728x90
The trapezoidal rule is a method for finding an approximate value for a definite integral. Suppose we have the definite integral
\begin{displaymath}\int_{a}^{b} f(x) \, dx\mbox{.}\end{displaymath}

First the area under the curve $y=f(x)$ is divided into $n$ strips, each of equal width $h=\frac{b-a}{n}$.

\begin{picture}(100,100) \put(10,50){\framebox (80,20){Picture!}} \end{picture}

The area under the curve $y=f(x)$ is divided into $n=4$ strips of thickness $h=\frac{b-a}{n}$. The area of each strip is then approximated to be that of a trapezium. The sum of these trapezoidal areas gives an approximation for our definite integral $\int_{a}^{b} f(x) \, dx$.

The shape of each strip is approximated to be like that of a trapezium. Hence the area of the first strip is approximately

\begin{displaymath}\frac{h}{2}\left(f(a)+f(a+h)\right)\mbox{,}\end{displaymath}

similarly we approximate the area of the $i$t strip to be
\begin{displaymath}\frac{h}{2}\left(f(a+(i-1)h)+f(a+ih)\right)\mbox{.}\end{displaymath}

Adding up these areas gives us an approximate value for our definite integral:
\begin{displaymath}\int_{a}^{b} f(x) \, dx \approx \sum_{i=1}^{n} \frac{h}{2}\left(f(a+(i-1)h)+f(a+ih)\right)\mbox{.}\end{displaymath}

This estimate for $\int_{a}^{b} f(x) \, dx$ generally improves as $n$ increases.
Example.
Let's use the trapezoidal rule to calculate an approximate value for the definite integral
\begin{displaymath}\int_{0}^{1} \sin x \, dx \mbox{.}\end{displaymath}

We shall divide the interval into $n=5$ strips each of width $h=\frac{b-a}{n}=\frac{1-0}{5}=0.2$. The trapezoidal rule then gives us:
$\displaystyle \int_{0}^{1} \sin x \, dx$ $\textstyle \approx$ $\displaystyle \sum_{i=1}^{5} \frac{1}{10}\left(\sin \left(\frac{i-1}{5}\right)+\sin \left(\frac{i}{5}\right)\right)$  
  $\textstyle \approx$ $\displaystyle \frac{1}{10} \left( \sin 0 + 2\sin 0.2 + 2\sin 0.4 + 2\sin 0.6 + 2\sin 0.8 + \sin 1 \right)$  
  $\textstyle \approx$ $\displaystyle 0.458164$  

Let's compare this with the true value:
$\displaystyle \int_{0}^{1} \sin x \, dx$ $\textstyle =$ $\displaystyle \left[-\cos x \right]_{0}^{1}$  
  $\textstyle =$ $\displaystyle -\cos 1 + \cos 0$  
  $\textstyle =$ $\displaystyle 1 - \cos 1$  

We find that $(1-\cos 1)-0.458164 \approx 0.0015$ which is very good considering we only took $n=5$ subintervals.

This simple method works well if the curvature of $f(x)$ is not too high. A better approximation for the definite integral can be obtained by using the more sophisticated Simpson's rule.

728x90

댓글