35 Numerical Integration
We have seen countless integrals in calculus and have become quite proficient in being able to evaluate integrals. We also saw how Riemann sums could be used to approximate the area under a curve by using mid-points or end points. The next two rules we will cover have a similar intention as Riemann sums the only requirement of these rules is that the integrals must be definite. As well, with using the Trapezoid and Simpson’s rule for approximation there is also the ability to calculate error just as we did previously with series.
29.1 Trapezoid Rule
We begin with the Trapezoid rule. Unlike the Riemann sums which used the sum of the areas of rectangles approximately fitted to the curve of a function to approximate the total area, with Trapezoid rule we include the area of fitted triangles associated with each rectangle. The diagram below gives the best representation to understand this concept.

We can see from this diagram that the rectangles we are familiar with from Riemann sums are built upon with triangular ends to better fit the curve. We define the formula for the Trapezoid rule as follows [37].
Theorem: Trapezoid Rule
Given the integral for  from
 from  to
 to  as
 as
      
We can approximate the integral using the Trapezoid rule as follows.
      ![Rendered by QuickLaTeX.com \begin{equation*} \int_{a}^{b}{f(x) \ dx} \approx T_{n}=\frac{\bigtriangleup x}{2} \left[ f(x_{0})+2f(x_{1})+2f(x_{2})+...+2f(x_{n-1})+f(x_{n})\right] \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-71df131bf8a3b11d6fd046d4b41ef434_l3.png)
Where  for
 for  intervals and
 intervals and  .
.
The idea behind the Trapezoid rule is that the approximation will become more precise as the number of intervals  grows.
 grows.
Example:
Evaluate the following integral with  intervals using the trapezoid rule [15].
 intervals using the trapezoid rule [15].
      
We begin by calculating  .
.
      
Now that we have found  , we calculate the values for
, we calculate the values for  at each point starting with
 at each point starting with  as always.
 as always.
      
Now substituting our found values into the trapezoid rule function and solve for the approximation.
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \int_{0}^{0.5}{(1-x^{2})^{5} \ dx} &\approx \frac{0.125}{2} [ f(a)+2f(a+\bigtriangleup x)+2f(a+2\bigtriangleup x)\\ & +2f(a+3\bigtriangleup x)+2f(a+4\bigtriangleup x)+f(b)]\\ &=(0.0625) \left[ 1+2\sqrt{\frac{63}{64}} +2\sqrt{\frac{15}{16}} +2\sqrt{\frac{55}{64}} + \sqrt{\frac{3}{4}} \right] \\ &=0.4775550114 \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-7712fcaa6ef0313631201570313bac86_l3.png)
Now that we have established how to evaluate an integral we need to address common ways of calculating the error. First off, looking back at the previous example we were able to evaluate the integral and produce a 10 decimal answer but this is a rounded off answer, in numerical methods we call this truncation. Therefore we need to be able to calculate the error with respect to this truncation. We define the formula for this error as follows.
Truncation Error:
Given an integral for function  from
 from  to
 to  . Using the Trapezoid rule to evaluate the integral we can find the truncation error of the integral as follows [16].
. Using the Trapezoid rule to evaluate the integral we can find the truncation error of the integral as follows [16].
Definition.
      
Branching out we can utilize this formula in two method, either the maximum error or average error method. We have these two unique methods because within the truncation formula we have a function,  . We need to be able to find the value for this if we are to complete the evaluation for the error.
. We need to be able to find the value for this if we are to complete the evaluation for the error.
Maximum Error
The maximum error is much like the approximate uncertainty we discussed in our section on analysis. We are focused on finding the greatest possible error, with this being said we would want to use the greatest value possible for  . Let us consider our previous example for
. Let us consider our previous example for  .
.
Example:
Given the following integral for  , calculate the maximum error.
, calculate the maximum error.
      
Let us first find the function for the second derivative of  .
.
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} f(x) &= (1-x^{2})^{0.5}=\sqrt{(1-x^{2})}\\ f'(x) &= (0.5)\cdot \frac{1}{\sqrt{(1-x^{2})}} \cdot (-2x) =- \frac{x}{\sqrt{(1-x^{2})}}\\ f''(x) &=- \frac{1}{\sqrt{(1-x^{2})}} + \left[ \frac{-x}{\sqrt{(1-x^{2})^{3}}}\cdot (-0.5)\cdot (-2x)\right] \\ &=- \frac{1}{\sqrt{(1-x^{2})}} - \frac{x^{2}}{\sqrt{(1-x^{2})^{3}}}\\ &=-\frac{1}{\sqrt{(1-x^{2})^{3}}} \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-5f3756272d15075de9de5d7ab9b99c38_l3.png)
Next, since  is an increasing function then the value for
 is an increasing function then the value for  at
 at  is the greatest value produced on the interval
 is the greatest value produced on the interval  . Thus we calculate
. Thus we calculate  for
 for  to be as follows.
 to be as follows.
      
Now we can substitute our known values into the truncation formula and find the error.
      
Thus we have found the greatest radius of uncertainty for our approximation of the integral, using the Trapezoid rule. Next, we look at the other method for approximating the error by the average.
Average Error
The average error requires us to calculate the average value for the derivative  . The equation is given as follows.
. The equation is given as follows.
      
This is the basic formula for finding the average value, when applied to the truncation error formula this means that  . Thus we can rewrite the truncation error formula with
. Thus we can rewrite the truncation error formula with  [16].
 [16].
      
Let us revisit our example again to calculate the average error of the Trapezoid rule for  .
.
Example:
Given the following integral for  , calculate the average error.
, calculate the average error.
      
Firstly since  then instead of finding the second derivative of the function we only need to find the first. Recall that our average formula utilizes
 then instead of finding the second derivative of the function we only need to find the first. Recall that our average formula utilizes  such that
 such that  . Thus we find the following derivative.
. Thus we find the following derivative.
      
Now we need to calculate  and
 and  . Recall that
. Recall that  and
 and  such that we have the following.
 such that we have the following.
      
Now that we have found all our values we can substitute them into our error formula.
      ![Rendered by QuickLaTeX.com \begin{equation*} E_{TRUN, avg}=-\frac{ \left( 0.125 \right)^{2} \left[ \left(-\frac{0.5}{\sqrt{0.75}} \right)-(0)\right] }{12} = 0.000752 \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-f7ca376948dd50baaf0154997d9253de_l3.png)
We should note that the average error is smaller than the maximum error, this is to be expected. This is also very helpful if the average error is, for some reason, larger than the maximum then the calculations need to be checked again. We now move on to an improved Trapezoid rule found in the Simpson’s rule.
29.2 Simpson’s 1/3 Rule
Through countless integration problems throughout mathematics we should have noticed how our approximation of an area is improved by smaller intervals which in turn means we need a greater amount of intervals on  . This is where Simpson’s
. This is where Simpson’s  rule comes in, this integration method is an improvement upon the Trapezoid rule as it utilized parabolas instead of Trapezoids to best fit the area under a curve. We can see this concept illustrated in the below diagram.
 rule comes in, this integration method is an improvement upon the Trapezoid rule as it utilized parabolas instead of Trapezoids to best fit the area under a curve. We can see this concept illustrated in the below diagram.

Here we can see that parabolic shapes are built upon the rectangle we know from Riemann sums. With this we can conform to the curve with better accuracy than with the Trapezoid rule’s triangular shapes. We have the formula for the Simpson’s  rule as follows.
 rule as follows.
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \int_{a}^{b}{f(x)dx} &= \frac{\bigtriangleup x}{3} [ f(a)+4f(a+\bigtriangleup x) +2f(a+2\bigtriangleup x) + 4f(a+3\bigtriangleup x)\\ &+ 2f(a+4\bigtriangleup x)+...+4f(b-\bigtriangleup x)+f(b)] \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-c5340e5d6b927cfd2070f486f03bb072_l3.png)
Let us use the same example as before but this time we apply the Simpson’s  method.
 method.
Example:
Evaluate the following integral with  intervals using the Simpson’s
 intervals using the Simpson’s  rule [15].
 rule [15].
      
For  we calculate
 we calculate  to be as follows.
 to be as follows.
      
Now we find the values for each  starting with
 starting with  .
.
      
Now that we have our values we can substitute them into our Simpson’s  rule formula.
 rule formula.
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \int_{0}^{0.5}{(1-x^{2})^{0.5} \ dx} &=\frac{\bigtriangleup x}{3} [f(a)+4f(a+ \bigtriangleup x)+2f(a+2\bigtriangleup x)\\ &+4f(a+3\bigtriangleup x)+f(b)]\\ &= \frac{0.125}{3} \left( 1+4\left( \sqrt{\frac{63}{64}} \right) +2\left( \sqrt{\frac{15}{16}} \right)\\ &+4\left( \sqrt{\frac{55}{64}} \right) +\sqrt{\frac{3}{4}} \right) \\ &=0.4783018038 \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-7c52ea4ba5b61e2f9e0b86081528cc02_l3.png)
We can compare these values to what we found for this same example using the trapezoid rule, and we will see these are all very close values. What we will really tell us if an improvement has been made is by comparing the errors found for Trapezoid rule versus Simpson’s  . We are given the truncation error formula for Simpson’s rule as follows.
. We are given the truncation error formula for Simpson’s rule as follows.
      
Using the same example as before we can calculate the maximum truncation error as follows.
Example:
Given the following integral for  , calculate the maximum error.
, calculate the maximum error.
      
Firstly we need to find the fourth derivative for  . We utilize the first two derivatives we found using Trapezoid rule
. We utilize the first two derivatives we found using Trapezoid rule
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} f(x) &= (1-x^{2})^{0.5}=\sqrt{(1-x^{2})}\\ f'(x) &= (0.5)\cdot \frac{1}{\sqrt{(1-x^{2})}} \cdot (-2x) =- \frac{x}{\sqrt{(1-x^{2})}}\\ f''(x) &=- \frac{1}{\sqrt{(1-x^{2})}} + \left[ \frac{-x}{\sqrt{(1-x^{2})^{3}}}\cdot (-0.5)\cdot (-2x)\right] \\ &=- \frac{1}{\sqrt{(1-x^{2})}} - \frac{x^{2}}{\sqrt{(1-x^{2})^{3}}}\\ &=-\frac{1}{\sqrt{(1-x^{2})^{3}}}\\ f^{3}(x)&=-\frac{1}{\sqrt{1-x^{2})^{5}}} \cdot (-1.5) \cdot (-2x)\\ &=-\frac{3x}{\sqrt{(1-x^{2})^{5}}}\\ f^{4}(x)&=-\frac{3}{\sqrt{(1-x^{2})^{5}}} + \left[ \frac{-3x}{\sqrt{(1-x^{2})^{7}}} \cdot (-2.5) \cdot (-2x) \right] \\ &=-\frac{12x^{2}+3}{\sqrt{(1-x^{2})^{7}}} \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-8466e7965d5e8126a5cc5e0bee10b0ee_l3.png)
Now we can calculate  at the maximum
 at the maximum  since
 since  is a decreasing function.
 is a decreasing function.
      
Now that we have all of our known values we can calculate the maximum truncation error as follows
      
This is a much smaller maximum truncation error than what we found using the Trapezoid rule. Let us now look at the average truncation error and compare to what we found using the Trapezoid rule. Recall that the average is calculated by the following.
      
Thus we can calculate the average, given the truncation for Simpson’s  requires
 requires  and
 and  , as the following.
, as the following.
      
Which results in the following formula for the average truncation error [16].
      
Now we can calculate the average truncation error for our example, this time for Simpson’s  rule.
 rule.
Example:
Given the following integral for  , calculate the average error.
, calculate the average error.
      
Firstly we need already found the third derivative for  from the maximum error to be
 from the maximum error to be
      
Thus we can calculate the third derivative for  and
 and  as follows.
 as follows.
      
Now that we have all our known values we can substitute our values in for the average truncation error formula.
      
Again we see that the average truncation error is much smaller for the Simpson’s  rule than for the Trapezoid rule. This supports our claim that the Simpson’s
 rule than for the Trapezoid rule. This supports our claim that the Simpson’s  rule is an improved version of the Trapezoid rule as we have seen by the simple improvement in error from Trapezoid to Simpson’s
 rule is an improved version of the Trapezoid rule as we have seen by the simple improvement in error from Trapezoid to Simpson’s  rule.
 rule.
Now so far we have seen integrals with even values of  . What happens if
. What happens if  is odd? This is where Simpson’s
 is odd? This is where Simpson’s  rule is utilized.
 rule is utilized.
29.3 Simpson’s 3/8 Rule
The first step of the Simpson’s  rule is to separate our integral into two integrals, one with an even amount of intervals and one with the odd remaining intervals. For the integral with an even amount of interval we simply apply the Simpson’s
 rule is to separate our integral into two integrals, one with an even amount of intervals and one with the odd remaining intervals. For the integral with an even amount of interval we simply apply the Simpson’s  rule. The idea behind the Simpson’s
 rule. The idea behind the Simpson’s  rule is that we initially want an odd integral with
 rule is that we initially want an odd integral with  intervals which gives us the formula
 intervals which gives us the formula
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \int_{a}^{b}{f(x)dx} &= \frac{b-a}{3}\cdot \frac{3}{8} \cdot [ f(a)+3f(a+\bigtriangleup x) +3f(a+2\bigtriangleup x) +\\ &...+3f(b-\bigtriangleup x)+f(b)] \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-ab6ff7cde6e68de03426d5c7a9696868_l3.png)
From here we see that 3 in the numerator and the 3 in the denominator cancel each other out leaving us with the approximation formula as follows.
      ![Rendered by QuickLaTeX.com \begin{equation*} \int_{a}^{b}{f(x)dx} = \frac{b-a}{8} [ f(a)+3f(a+\bigtriangleup x) +3f(a+2\bigtriangleup x) +...+3f(b-\bigtriangleup x)+f(b)] \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-baea6c682d9c37954d4dca1570f0ab03_l3.png)
Utilizing a similar example to the one used to approximate with the Trapezoid and Simpson’s  rule we now apply Simpson’s
 rule we now apply Simpson’s  rule.
 rule.
Example:
Evaluate the following integral using Simpson’s rules with  [15].
 [15].
      
Firstly we need to make sure  is odd. We calculate
 is odd. We calculate  by the following.
 by the following.
      
Thus we need to rewrite the integral into two, making sure to have one integral with  intervals. we calculate the interval for each integral by letting
 intervals. we calculate the interval for each integral by letting  thus out first integral has
 thus out first integral has  and
 and  and our second integral has
 and our second integral has  and
 and  .
.
      
Let us evaluate the first integral using Simpson’s  rule, we first calculate the values for
 rule, we first calculate the values for  starting with
 starting with  .
.
      
Now that we have found all are values, we can substitute them into our Simpson’s  formula for evaluating the integral.
 formula for evaluating the integral.
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \int_{0}^{0.375}{(1-x^{2})^{0.5} \ dx} &= \frac{0.375-0}{8} \left[ 1+3\left( \sqrt{\frac{63}{64}} \right) +3 \left( \sqrt{\frac{15}{16}} \right) +\left( \sqrt{\frac{55}{64}} \right) \right]\\ &=0.366011 \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-f217af4ff19a4c626c74d9379ef9bcab_l3.png)
Now, we need to evaluate the second integral. We begin by finding our values for  starting with
 starting with  .
.
      
Now that we have found all our values we can substitute them into our formula for Simpson’s  rule for evaluating the integral.
 rule for evaluating the integral.
      ![Rendered by QuickLaTeX.com \begin{equation*} \begin{split} \int_{0.375}^{0.875}{(1-x^{2})^{0.5} \ dx}&=\frac{0.125}{3} \left[ \sqrt{\frac{55}{64}} +4 \sqrt{\frac{3}{4}} +2\sqrt{\frac{39}{64}} + 4\sqrt{\frac{7}{16}} + \sqrt{\frac{15}{64}} \right]\\ &=0.378427 \end{split} \end{equation*}](https://iu.pressbooks.pub/app/uploads/quicklatex/quicklatex.com-d350cf6656f071e6af6813d296b6eaa3_l3.png)
Now we need to add the two integrals together to complete our evaluation.
      
Now we should evaluate the average and maximum errors to see if this is a good approximation or not. Just as Trapezoid and Simpson’s  rules have their own average and maximum error formulas, the same goes for Simpson’s
 rules have their own average and maximum error formulas, the same goes for Simpson’s  rule. We begin with the formula for the truncation error of Simpson’s
 rule. We begin with the formula for the truncation error of Simpson’s  rule.
 rule.
      
Beginning with the maximum error we simply find when  is at its maximum over the interval
 is at its maximum over the interval  . In our example we split our original integral into two and applied the
. In our example we split our original integral into two and applied the  rule to one integral and the
 rule to one integral and the  rule to the other, accordingly we need to find the maximum error as well.
 rule to the other, accordingly we need to find the maximum error as well.
Example:
We start with the first integral, with  intervals, the integral is as follows.
 intervals, the integral is as follows.
      
In our previous calculation for the maximum truncation using Simpson’s  rule we found
 rule we found  as
 as
      
If we were to graph this function we would see that this is an increasing function which means on the interval  the maximum is when
 the maximum is when  . Thus we can calculate the maximum truncation error.
. Thus we can calculate the maximum truncation error.
      
Next, we need to calculate the maximum truncation error for the second integral.
      
Since this integral qualifies for Simpson’s  rule we use the Simpson’s
 rule we use the Simpson’s  rule maximum truncation error given by the following formula.
 rule maximum truncation error given by the following formula.
      
Again since we know that  is an increasing function the maximum will be reached at
 is an increasing function the maximum will be reached at  , thus we have the following calculation.
, thus we have the following calculation.
      
Just as we combined our two approximations for the evaluation of the integral, we do the same for the maximum error. Thus our maximum error for the original integral is as follows.
      
Next we need to calculate the average truncation error. In Simpson’s  rule we are introduced to finding the average of
 rule we are introduced to finding the average of  by the formula
 by the formula
      
Keeping the truncation formula for Simpson’s  rule as is we can calculate our average truncation error for our example. To calculate the average truncation error, we use the same idea of summing two truncation error calculations as we did in the example previous. This time we apply the average calculations. Firstly we know the formula for the average
 rule as is we can calculate our average truncation error for our example. To calculate the average truncation error, we use the same idea of summing two truncation error calculations as we did in the example previous. This time we apply the average calculations. Firstly we know the formula for the average  is given as follows.
 is given as follows.
      
From here we can simplify the formula for the average truncation error.
      
Now let us apply this formula to our example.
Example:
We begin with out first of two integrals.
      
We found  previously in our work with Simpson’s
 previously in our work with Simpson’s  rule.
 rule.
      
We know  and
 and  thus we calculate
 thus we calculate  and
 and  .
.
      
Now we substitute these values into our formula for the average truncation error.
      
Next we need to calculate the average truncation error for the second integral, using Simpson’s  rule. We begin with finding the values of
 rule. We begin with finding the values of  and
 and  for
 for  and
 and  .
.
      
Now we can apply the average truncation error formula for Simpson’s  rule.
 rule.
      
Finally, we combine the two average truncation errors to find the average truncation error for the original integral.
      
Thus we have covered numerical integration by Trapezoid and Simpson’s  rule for even values of
 rule for even values of  and we addressed using Simpson’s
 and we addressed using Simpson’s  rule for odd
 rule for odd  . We also covered how to calculate the maximum and average truncation errors for each of our approximations. From integration approximations we move to calculating the root of nonlinear equations in our next section.
. We also covered how to calculate the maximum and average truncation errors for each of our approximations. From integration approximations we move to calculating the root of nonlinear equations in our next section.
