Addaptive Quadrarture
Addaptive Quadrarture
In addition, the estimate and error associated with either application can be represented
generally as
I 5 I(h) 1 E(h) (22.13)
where I 5 the exact value of the integral, I(h) 5 the approximation from an n-segment
application of the Simpson’s 1y3 rule with step size h 5 (b 2 a)yn, and E(h) 5 the
corresponding truncation error.
Using an approach similar to Richardson extrapolation, we can derive an estimate
for the error of the more refined estimate, I(h2), as a function of the difference between
the two integral estimates,
1
E(h2 ) 5 [I(h2 ) 2 I(h1 )] (22.14)
15
The error can then be added to I(h2) to generate an even better estimate
1
I 5 I(h2 ) 1 [I(h2 ) 2 I(h1 )] (22.15)
15
This result is equivalent to Boole’s rule.
The equations developed above can now be combined into an efficient algorithm.
Figure 22.5 presents pseudocode for such an algorithm that is based on a MATLAB
software M-file developed by Cleve Moler (2005).
The function consists of a main calling function, quadapt, along with a recursive
function, qstep, that actually performs the integration. As set up in Fig. 22.5, both qadapt
and qstep must have access to another function, f, that evaluates the integrand.
The main calling function, quadapt, is passed the integration limits, a and b. After
setting the tolerance, the function evaluations required for the initial application of Simpson’s
1y3 rule (Eq. 22.10) are computed. These values along with the integration limits are then
passed to qstep. Within qstep, the remaining step sizes and function values are deter-
mined and the two integral estimates (Eqs. 22.10 and 22.11) are computed.
At this point, the error is estimated as the absolute difference between the integral
estimates. Depending on the value of the error, two things can then happen:
1) If the error is less than or equal to the tolerance, Boole’s rule is generated, the func-
tion terminates and the result is returned.
2) If the error is larger than the tolerance, qstep is invoked twice to evaluate each of
the two subintervals of the current call.
642 INTEGRATION OF EQUATIONS
The two recursive calls in the second step represent the real beauty of this algorithm.
They just keep subdividing until the tolerance is met. Once this occurs, their results are
passed back up the recursive path, combining with the other integral estimates along the
way. The process ends when the final call is satisfied and the total integral is evaluated
and returned to the main calling function.
It should be stressed that the algorithm in Fig. 22.5 is a stripped down version of
the quad function which is the professional quadrature function employed in MATLAB.
Thus, it does not guard against failure such as cases where integrals do not exist.
Nevertheless, it works just fine for many applications, and certainly serves to illustrate
how adaptive quadrature works.