DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

download DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

of 7

Transcript of DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

  • 8/8/2019 DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

    1/7

    A doubly-adaptive Clenshaw-Curtis quadraturemethodJ. OliverComputing Centre, University of Essex, Wivenhoe Park, Colchester, Essex

    An automatic integration algorithm, based on the Clenshaw-Curtis method, is described which canadapt either the formula in use or the interval subdivision at any stage. Numerical tests demonstrateits competitiveness with both whole-interval formulae and adaptive algorithms for well and badlybehaved integrands.(Received September 1971)

    1. IntroductionThe various automatic general-purpose algorithms so farproposed for evaluating a definite integral,

    -i:can conveniently be classified as either adaptive or non-adaptive. In the former, the desired accuracy is sought byprogressively subdividing the interval of integration accordingto the computed behaviour of the integrand, and applying thesame formula over each subinterval. This pre-selected formulais usually one employing only a small number of integrandvalues in order to minimise their loss on subdivision, and istherefore of low order. The alternative, whole-interval,approach is either to apply a family of related formulae ofprogressively increasing order, or to use a composite rule withan increasing number of points, but in either case the formulais applied uniformly over the entire range without regard to thebehaviour of the integrand.It is generally supposed that an adaptive technique, such asthat of O'Hara and Smith (1969), will be the more efficient forintegrands which are difficult to app roximate over a small par tof [a, >]. Numerical experiments support this view, providedefficiency is measured by the number of integrand values neededto achieve an acceptable estimated accuracy. On the other handthe non-adaptive approach is superior when the behaviour ofthe integrand is uniform over the entire interval. If, therefore,a single automatic integrator is desired which can be applied toboth classes of problem, then neither type of method is ideal.We shall present here an algorithm which is designed tobehave like either an adaptive or a whole-interval method,depending upon the nature of the problem. Since it does thisby adapting both the integration formula and the intervalsubdivision according to the computed characteristics of theintegrand, we shall refer to it as a 'doubly-adaptive' algorithm.On the basis of numerical comparisons we shall argue that ithas much to recommend it as an automatic general-purposeintegrator.2. The integration formulaSince our adaptive strategy involves examining the computedcoefficients in the expansion of the integrand as a Chebyshevseries, it is natural to use the integration formulae due toClenshaw and Curtis (1960) since these provide the requiredcoefficients without the need for additional integrand values.The Clenshaw-Curtis method essentially approximates /(/)over any subinterval [a h, a + h] by the polynomial ofdegree n,

    r = 0 (2 )collocating with/(a + hx ) at the n + 1 pointsVolume 15 Number 2

    in, = cos - ( i = 0 , l , . . . ,so that the coefficients are given by

    (3 )

    a_=/ (a + hx t) Tr(x.) (r = 0, 1, . . ., n - 1)

    (a + hxd TXi) (r = n) .(4 )

    The integral off(t) over this subinterval is then approximatedby that of the polynomial, namelyhx t) (5a)

    whereV

    jr = 0 (r 0 = 0, 1,. . . , n) .

    O'Hara and Smith (1968) showed that the error in / can beexpanded in the form, taking n as even,(6 )

    where en+2s are appropriate constants depending on n and s,and An+2s are the coefficients in the exact representation of /(f ),/ (a + hx) ' A rTr{x) ( - 1 < x < 1) , (7)

    and they suggested basing an estimate of En on twice the firstterm in the series (6) provided the series was sufficiently rapid lyconvergent.In a somewhat similar manner, we estimate the rate of de-crease, K, of the even coefficients An+2, by taking

    gn-2 n -4 - I I (8 )

    omitting the last ratio when n = 4, and similarly approximate\A_n+2\ by\An+2\ = max {K\an\, K 2\an.2\, K3\an.4\} = K3\an.^\ . (?)In order to obtain an analogous estimate of En when the seriesconverges more slowly, however, we have calculated the valuesKn(a) of K for which

    s = ic-n bn+2s\ = V ,n+2\ (10)

    141

  • 8/8/2019 DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

    2/7

    Table 1n

    48163264128

    Critical

    0-2720-1440-2430-2830-2900-292

    convergence*(4)

    0-6060-2570-3660-4680-4940-499

    rates Kn(a)*(8)0-8110-3760-4490-5650-6340-644

    and K**(I6)0-9080-5110-5220-6240-7140-745

    K*0-4550-5500-6670-7800-855

    for a = 2, 4, 8 and 16, and these are given in Table 1. Thevalues for a = 2 agree, of course, with those obtained byO'Hara and Smith (1968, Table 1).Provided K < A"n(16), this enables us to estimate En by = ha\en+ 2\ \An + 2\ = ha (n2 - 1) (n2 - 9)

    where a is the smallest of 2, 4, 8, 16 such thatK < Kn(a) .

    \An+2\ ( I D

    (12)When K < Kn{2), this error estimate is similar to that of O'Haraand Smith (1968), though somewhat sharper for small K.3. The adaptive strategyAs is usual in adaptive algorithms, we first attempt to satisfythe error requirement over the entire interval [a, b], and ifnecessary repeatedly subdivide the range and treat each partseparately. In order to minimise the number of integrand valueslost on subdivision, we first apply to each new subinterval theClenshaw-Curtis formula of lowest order which is consistentwith a reasonable error estimate of the type described above,namely the 5-point formula (n = 4) with the abscissae

    x4 = - 1 , x3 = - 1/V2, x2 = 0, Xi = 1/V2, x0 = 1.If subdivision is effected by halving, then only the twointegrand values at x^ and x3 are lost, though this numberincreases to n 2 if an (n + l)-point formula is currently in

    use over the whole subinterval, with n > 8. Attention is thenfocused on the left-hand interval, while the integrand value atx0 is stored for future use. By excluding any subinterval fromfurther consideration once the error requirement over it hasbeen fulfilled, the number of integrand values which must bestored at any time is thus reduced to a maximum of m, wherethe smallest subinterval is of length (b - a)/2m.Cranley and Patterson (1971, Section 3) have argued that suchan adaptive scheme is unacceptable since it does not meet thesecond of the requirements which they consider essential for anautomatic integrator, namely that 'it should be possible toimprove confidence in any result without performing an in-ordinate amount of labour'. We do not, however, accept thenecessity in practice of their postulated requirement, andalthough it is certainly true that a computed error estimate is

    inevitably fallible, we recall O'Hara and Smith's pertinentobservation (1969, Section 2) that 'if the interval is subdividedseveral times, the quadrature over the whole interval is verymuch more reliable than the quadrature over each subinterval'.This belief is encouraged by the results described below,although the algorithm, like all others mentioned here, doesoccasionally fail. There appears, therefore, to be no real justi-fication for employing the alternative subdivision modelproposed by Cranley and Patterson, with its almost unlimitedstorage requirement resulting from the need to retain integrandvalues over all subintervals until the entire quadrature iscomplete.Where the algorithm described in this paper departs essen-tially from previous adaptive algorithms is in its ability to apply

    142

    the Clenshaw-Curtis (In + l)-point formula over the wholesubinterval as an alternative to subdivision when the (n + 1)-point formula has failed to meet the local error requirement.The strategy for decision was advanced in Oliver (1971), andessentially involves subdividing only if the computed co-efficients are sufficiently slowly convergent as measured by thevalue of K in (8). More precisely, subdivision takes place if Kexceeds the critical value K* given in Table 1; this is the valuefor which the errors resulting from halving the subinterval andfrom doubling n are expected to be equal under the assumptionsexplained in Oliver (1971).After subdivision when n > 8, instead of re-applying the(n + l)-point formula over each half, it seems more sensible torevert to the 5-point formula since no integrand values will bewasted even if the order is then increased to n by repeateddoubling, while the number lost will be minimised shouldfurther subdivision be immediately required. In fact one wouldhope that the algorithm would detect the slow convergence ofthe Chebyshev coefficients, and hence the need to subdivide,without taking n > 4, and this is indeed often the case.4. Error requirementsWe shall assume here that the integral / is required correct to aspecified absolute accuracy e. Fulfilment of a relative accuracyrequirement is more difficult with methods involving sub-division than with whole-interval formulae, since a reasonableapproximation to the integral over the whole interval may wellnot be available during the computation, but O'Hara andSmith (1969) have suggested a possible strategy for this case.As they also pointed out, there is no single obvious choice ofabsolute error requirement over a subinterval, and this is to alarge extent a matter of personal preference. When consideringany subinterval [a - h, a + h], we suggest allowing a maxi-mum absolute error of

    (e e*) x max 2hb -{OL- h)' (13)where e* is the estimated total error accumulated so far.To estimate the local error we first calculate En as in (11)

    provided K < Kn(\6), but if > 8 we take \In - In/2\ shouldthis be smaller. When K > Kn(l6), we regard the method ofSection 2 as being too unreliable and therefore necessarilytake \In - In/2\ as an error estimate, or split the range shouldn = 4 since fn/2 is not available. As a precaution when n > 8,we check that the error estimate before n was doubled bounds[/ - In/2\, and if it does not then we take |/n - Inl2\ rather thanEn as the estimated error, and continue to do this until inte-gration over the current section of the interval is complete.Again for safety, the result of a 5-point formula over the wholeinterval is automatically rejected, so that the minimum numberof integrand evaluations is nine (in agreement with the policyof O'Hara and Smith, 1968, Section 3.5).In order to reduce repeated subdivision when the errorestimate 4. is very conservative, as can happen at a discon-

    tinuity of the integrand or its derivative, the weak error estimate2/i[max

    i- min (14)

    is employed whenever a subinterval [a - h, a + h~] is to besplit, and if this is no greater than the local error requirementthen the subinterval is accepted, with a contribution to theintegral of{/(*,)} min (15)

    5. Rounding errorsCertain of those features of our algorithm which are designedto allow for the finite word-length of the computer should be

    The Computer Journal

  • 8/8/2019 DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

    3/7

    noted. The quadrature over a subinterval of length 2h is alwaysconcluded if the estimated error over it should fall below therounding error level, which is taken, for simplicity, ashr\ max |/(x,)| (16)

    where r\ is a small multiple, 16 say, of 2 for a machine with afloating point mantissa of / binary digits. This could of coursebe modified if a more accurate assessment of the errors in/Or,) could be made (Lyness, 1969).As previously indicated in (13), the partial sum, *, of themagnitudes of the estimated absolute errors over the subinter-vals is used to assess the maximum allowable error over the

    remaining subintervals. If rounding errors should becomedominant in the manner just described, then it is possible thate* may become very close to, or even exceed e. In such a casewe replace (e - e*) in (13) by the more reasonable requiremente*/10. This inevitably introduces the possibility that the desiredaccuracy may not be attained, particularly when this is com-parable with the basic machine accuracy, though this has nothappened in the numerical experiments reported below, and inany case the final value of e* should indicate such an occurrence.Indeed this final value can always be used, if desired, as aguide to the actual error, although as the results indicate, it

    would be unwise to interpret it as a strict upper bound.6. ResultsIn order to test the reliability of this doubly-adaptive algorithmwe applied an ALGOL 60 version of it (Appendix 1), usingan 1CL 1909 with a 37-bit mantissa, to the following 18problems listed by O'Hara and Smith (1968, 1969):

    1. exdxdx

    o 1 + cos xdx

    i: 5 + 4 cos xdx+ X

    1 dx

    I'r dx+ 25x2i-5x4

    /* 1 JJo 1 - 0 !

    8. V 4>{x)dxJo9. 5/4) + \ x - |(x - lY'3)dxJo.of' * .

    Jo 1 - 0-998x411 f1 dx"Jo 1 - 0 - 9 8 x 412. I ' |x + i | 1 / 2 d x

    J o r3Jo 1 +

    + 256(x - f ) 220dx

    6400(x - V17/5)2Volume 15 Number 2

    15 .16.17 .

    o

    18. owhere

    and

    Jxdx

    x cos2 20x dx:)dxdx

    - 100x2

    \e x, x < +;

    \.In each case an approximation to / was successfully obtainedhaving a smaller absolute error than the specified tolerance e,for seven different values of between 10" 2 and 10~8. Further-

    more, the final estimated error e* always formed a bound on theactual error, in contrast to the whole-interval formulaedescribed below.As a much more stringent test, following the example of

    O'Hara and Smith, the variable t was changed to y in eachintegral, wheret = ft + a b a \a{y a)a) + (y - b)']-a)-(y- b)\

    to give a set of distorted integrals dependent on the arbitraryparameter a,Cb C f b - a T/ = f{t) dt=\ a /(*(>>)) dy . (18)J a Ja la(y - a) - (y - fe)J

    The algorithm was then applied to the second integral for 21values of a between 0-5 and 2-5, and for the same seven differentaccuracies e, giving a total of 147 tests for each basic problem,and 2,646 altogether (including the non-distorted case ofa = 10).Although the algorithm converged to a result in every case,we found that it failed, in the sense that the actual errorexceeded the tolerated error s, on 54 occasions. These aresummarised in Table 2, which also shows the smaller number offailures obtained with an ALGOL version of O'Hara andSmith's (1969) adaptive subdivision algorithm SPLITABS.The majority of the failures occurred for problems 8 and 12,which have a first derivative with a discontinuity and singu-larity respectively, and for the highly oscillatory problem 16(though only for e = 10~2).Table 2 Number of failures of adaptive algorithms on test

    problemsPROBLEM DOUBLY-ADAPTIVE SPLITABS57810111213141617TOTAL

    11102226128154

    002008230015

    143

  • 8/8/2019 DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

    4/7

    Clearly O'Hara and Smith's algorithm offers greater reli-ability, as the authors intended it should, though as we shallsee this is at the expense of significantly m ore com putation. It isalso worth noting that those failures which did occur were forsomewhat extreme problems.Not surprisingly, in all the above cases, the error estimate e*gave no warning of the failure, and consequently it shoulddefinitely be regarded as only an indication of the actual error(though it did in fact form an upper bound in 94-0% of theproblems for the doubly-adaptive algorithm and 94-7% forSPLITABS).In order to compare efficiencies, we also evaluated the undis-torted integrals (a = 1 0) for the same values of e using therational extrapolation algorithm of Bulirsch and Stoer (1967).Unfortunately this repeatedly either returned too inaccurate avalue of /, or else failed to converge at all, and is therefore n otincluded in the comparison which follows.The doubly-adaptive algorithm proved consistently to besignificantly more efficient than that of O'Hara and Smith, asexemplified by Figs. 1-4 in which are shown the num ber ofintegrand values used by the algorithms for the variousrequested tolerances e. (The lines joining the points have nosignificance; they simply link together the points relating toeach adaptive method.) In fact SPLITABS was better only onproblem 8, and then only marginally so as may be seen fromFig. 2.The following whole-interval formulae were also used forcomparison:1. The Gauss-Legendre formulae with 2,4, 8 ,. . ., 256 points.2. The general formulae of Patterson (1968) involving 3, 7,15, . . ., 255 points.3. The Clenshaw -Curtis formulae based on 3, 5, 9, . . . , 257points (but without O'Hara and Smith's error estimationprocess since it is not universally valid).A variety of algorithms can be constructed using these formulae,so we chose the most obvious one in which formulae ofincreasingly higher order are applied, with the differencebetween two successive values forming an error estimate (asused by Patterson, 1972). Our comparison is therefore basedon the num ber of integrand values needed to achieve an accept-able error estimate, rather than an acceptable error, since it isthe former which is used in practice to determine the con-vergence of an algo rithm. This means, of course, that the actualerr or with such a whole-interval algorithm will usually be muchsmaller than that requested (and also that estimated), so thatthe adaptive approach is in no way at a disadvantage in thisrespect.Interpreting failure for the whole-interval formulae asmeaning that the error estimate exceeds the actual error, wefound the following number of failures occurred out of 126tests (108 for Patterson) on the undistorted integrals:

    Gauss: 10.Patterson: 5.Clenshaw-Curtis: 5.While such errors would be immaterial if the incorrect errorestimate exceeded the tolerance e, so that a higher order formulawas then applied, this would not occur if the estimated errorwas smaller than and the final error might then be too large.Thus such failures are a measure of the unreliability of thesewhole-interval methods, though not as serious as those of theadaptive algorithms. We recall that neither the doubly-adaptivealgorithm nor that of O'Hara and Smith experienced anyfailures for the undistorted integrals.The number of integrand values which are needed to achievea given tolerance e are also shown in Figs. 1-4 for the threewhole-interval formulae. (Here the lines do have significancedue to the inflexibility in the numb er of integrand values whichcan be used.)

    Fig. 1 (problem 2) is typical of the results for the relativelyeasy integrals 1-7, and indicates that although no singlealgorithm is the most efficient for all values of e between 10" 2and 10"8, that described here is at least as good as any otheroverall.Its superiority over the whole-interval formulae is, however,very evident for problems 8-14, as is typified by Fig. 2 (problem8). Note here that even with 255 abscissae, the Patterson for-mulae can only achieve an estimated accuracy of 1-37 x 10 "5(the actual error is in fact 6-37 x 10" 5), pointing to the factthat if greater accuracy is required than can be achieved withthe highest order formula available, then all the integrandvalues must be abandoned and the range of integration split(Patterson, 1971), while the same applies to the other whole-interval methods. This can be a serious disadvantage with'difficult' integrals, and in fact a similar situation arises withproblems 9, 12, 14 and 17.

    6

    S

    4

    3

    2

    1

    1

    -

    1

    1

    -*

    1

    1

    1

    1 1 1 13

    / '

    1

    1 _

    I I-3 -5 -6 -7 -8

    Log , 0 EFig. 1. A comparison of th e numb er, A', of integrand evaluationsrequired to achieve a tolerance E when integrating problem 2 ,

    fJoJo 1 + cos x 'by the methods: 1. Doubly-adaptive algorithm; 2. O'Hara andSmith's interval subdivision; 3. Gauss; 4. Patterson; 5.Clenshaw-Curtis.7

    f C

    5

    4

    3

    I ! 3 | | | |4

    ~. ^"" " 2

    I i I 1 1 1-1 -2 -3 -4 -5

    L9,o EFig. 2. As for Fig. 1 but for problem 8,-6

    rJo144 The Computer Journal

  • 8/8/2019 DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

    5/7

    9

    51 8

    6 -

    - 1

    1 1 1 1

    ^ T ^//

    ///i i i i

    1y

    1y

    53

    4

    1

    1

    -1

    -2 - 3 -5 - 6 -7

    Fig. 3. As for Fig. 1 but for problem 16,x c o s 2 20 x dx .

    10

    9 -

    8 -

    7

    6

    5

    3 -

    1

    ///

    /1

    I

    1 1 1 1 1

    r "r

    i/7 r

    i

    -*" -

    i i i i

    i

    4- 2^ 1

    -

    -2 - 3 -4 -5L 9,0 E

    - 6 -7

    Fig. 4. As for Fig. 1 but for problem 15,

    rJo dx .In the final group of four integrals, problems 15-18, thepresent algorithm was less efficient than Patterson andClenshaw-Curtis. For prob lem 16, shown in Fig. 3, even Gaus swas more efficient, but this is not typical. We therefore show inFig. 4 the next least favourable result, namely problem 15, inwhich the doubly-adaptive algorithm is by no means totallyoutclassed.

    7. ConclusionsWe conclude, therefore, that the algorithm proposed here ismarkedly superior to those currently in use for several of the

    test problems, and is not significantly less efficient, except forproblem 16, for the remaining integrals. Furth erm ore , itachieved requested tolerances up to 1 0~ 8 for all the undistortedintegrals tested, which the whole-interval me thod s occasionallyfailed to do, limited as they were to using a fixed maximumnumber of abscissae.On the oth er han d its superior ity, in terms of efficiency, ov erthe interval subdivision algorithm of O'Hara and Smith wasachieved at the expense of somewhat less reliability for certainextreme problems, and these two apparen tly conflicting req uire-ments must therefore be weighed carefully against one another.Despite this disadvantage, however, the strategy of adaptingboth order and subdivision, and thereby attempting to combinethe best features of adaptive subdivision and of whole-intervalformulae, appears to be a fruitful one in the context of auto-matic integrators, particularly as this represents the first attem ptat developing such an algorithm.Appendix IAlgorithmA D O U B L Y - A D A P TI V E A U T O M A T I C I N T E G R A T O RThis general-purpose algorithm evaluates a definite integral,

    I = \ f{x)dx,using the doubly-adapt ive quadrature method, and is equal lyapplicable to both well and badly behaved integrands.procedure adapquad ( /, a, b, eps, ace, eta, divmax , arts, error,F A I L ) ;value a, b, eps, ace, eta, divmax; integer divmax;real a, b, eps, ace, eta, arts, error; real procedure/ ; label FAIL;comment The procedure calculates an approximate value ansof the definite integral / of {x) between the limits a and b. T h eerror | / ans\ should not exceed the requested tolerance, eps,unless dominated by errors in the integrand values. Therelative accuracy of the values of f(x) should be input in ace,but this may be set to zero if f(x) is available to machineaccuracy. For a computer with t binary places in the mantissafor floating point arithmetic, eta should equal 2] t on entry.On exit error will contain an estimate of, but not necessarily abound on \I ans\. The procedure is left by the emergencyexit FAIL if /c an no t be es t imated without considering smallersubintervals than (6 fl)/2| divmax;

    begin integer i,j, m, mmax , n, nl, nm ax, max rule, order, div;real c, cprev, e, eprev, fmax, fmin, h, hmin, int, intprev, k,k\,kl, pi, re, x, xa, xb, xc;array ec [1 : 6 ] , / y , xs [O.clivmax \~\,fx, w\ [ 0 : 1 2 8 ] , sigma[1:6, 0:4], / [0:64], w [3:128];boolean caution;real procedure cheb (x, a); value x;real x; array a;comment Sums a Chebyshev series of degree n, whosecoefficients are contained in a[0~\, . . . , a[n], at the point x;begin integer r; real bO, b\, bl, twox;b\ := 0 ; bO := 0-5 x a [] ; twox : = x + x;for r : = n 1 step - 1 until 1 dobeginbl := 41 ; 61 := bO ;bO : = twox x 61 - bl + a[r]end;cheb := x x 60 - 61 + 0-5 x a[ 0]end of procedure cheb;procedure quadrule;comment Calculates the new abscissae xt, x3, . . ., xn/2-i an d

    Volume 15 Number 2 145

  • 8/8/2019 DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

    6/7

    weights wu .. ., wn/2 in the Clenshaw-Curtis (n + l)-pointquadrature formula when n increases to a value greater thanits previous maximum, maxrule;begin integer /;for i : = 1 step 2 until 2 1 dot [i x m] : = cos(pi x i/ri);for i : = 0-5 x maxrule + 2 step 2 until n dobeginw\ [i - 1] := 0 ; vl [i] := l/(z x / - 1)end;for /" := 1 step 1 until nl dow [nl 4- i] := 4 x c/ze> (t [i x m], wl)/;maxrule := wend of procedure quadrule;

    an s := error := 0;if a = b then goto COM PLETE ;if a > b thenbeginc := b; b := a; a := cend;/>/ := 3-141592653590; hmin := {b - a)/2fif ace < eta then ace : eta; ace := 16 x ace;x := 4; xa : = 64;for i : = 1 step 1 until 6 dobeginec [i] : = xa/((x x x ]) x (x x x 9));x : = x + x; xa : = xa + xaend;comment Critical values of/:;

    0]1]2]3]

    sigma [1sigma [1sigma [1sigma [1[1 ,4 ][2 , 0].sigma [2, 1]^ m o [ 2 , 2 ]sigma [2, 3]j/g/wa [2, 4]sigma [3, 0]j/gnja [3, 1]sigma [3, 2]sigma [3, 3].yig/wa [3, 4]sigma [4, 0]j/gma [4, 1]sigma [4, 2]sigma [4, 3]j/g/wa [4, 4]sigma [5, 0]j/g/wa [5, 1]sigma [5, 2]sigma [5, 3]s/gma [5, 4]sigma [6, 0]sigma [6, 1]s/^mfl [6, 2]sigma [6, 3]j /gma [6, 4]

    = 0-455;= 0-272;= 0-606;= 0-811;= 0-908;= 0-55;= 0144;= 0-257;= 0-376;= 0-511;= 0-667;= 0-243;= 0-366;= 0-449;= 0-522;= 0-78;= 0-283;= 0-468;= 0-565;= 0-624;= 0-855;= 0-290;= 0-494;= 0-634;= 0-714;= - 10;= 0-292;= 0-499;= 0-644;0-745;n := 4; 2 := 2; nmax := 128;m : = mmax := nmax/n;/[0] := 1; t[nmax\2] := 0;maxrule := div := 0; w\ [0] := 1;quadrule;xa := xc := a; xb := b;fx [ 0 ] = / ( 6 ) ; fx [ ] : = / ( ) ;

    NEXT:comment Integration over new subinterval;n := 4; ri l := 2; m := mmax; order := 1;caution : = (if xa < xc then true else false);h := xb xa; k\ := h/(b xa);if/cl < 01 thenfcl := 0-1;h :=0-5 x h;j := 1;A[ / i2 ] : = f(xa + h);fmin : = fmax : = fx [0];iff max < fx [ ] then fmax : = fx [n ] elseKfmin > fx [ ] then fmin : = fx [n ] ;if fmax < fx [nl] then fmax : = fx [2] elseif fmin > fx [2] then/mm : = fx [nl];

    AGAIN:comment Calculate new integrand values, Chebyshev co-efficients and error estimate;for / := 1 step j until nl 1 dobegin/ * [ / ] : = /(jfa + (1 + / [/ x mj) x h);if fmax < fx [i] then fmax : = fx [i] elseif fmin > fx [i ] then fmin : = fx [ i ] ;fx\n - i] : = /( xo + (1 - f[i x m]) x h);if fmax fx[n i] then fmin : = fx[n Qend of new integrand values;re : = ace x (if abs{fmax) > abs(fmin) then absffmax) elseabs(fminj);j : = if n = 4 then 4 else 6; fc : = 0;c := abs(cheb(l,fx))/n;for i: 2 step 2 until j dobeginx : = if / < nl then t [i x m] else t [( i) x w] ;cprev : = c; c := abs(cheb(x, fx))/nl;if c > re thenbeginif k < cprev/c then k : = cprev/cendelse if cprev > re then A: : = 1end calculation of coefficients and k;

    if k > sigma [order, 4] thenbeginif n = 4 then goto SPLIT else goto EVALend;if n = 4 then cprev : = celse if cprev < re then cprev := k x c;e := h x cprev x ec [order] x k x k x k;for i := 0, / + 1 while k > sigma [order, i] do e : = 2 x e;re := /i x re;EVAL:comment Evaluate integral and select appropriate errorestimate;int : = w\[ri] x {fx [0] + fx [n]) + w [n] x fx [nl];for i := 1 step 1 until 2 1 do

    wif : = int + w [nl + i] x (fx [i] +fx[n- i]);int := h x int;if n = 4 then goto TEST ;c := abs(int intprev);if c > eprev thenbegincaution : true;if xc < xb then xc := xbendelse caution := false;if fc > s/gwa [order, 4] v caution then e : = c;if e > c then e := c;TEST:comment Finish consideration of current subinterval if localerror acceptable;

    146 The Computer Journal

  • 8/8/2019 DubliAdaptiveClenshaw-Curtis Quadrature Methodpdf

    7/7

    if e < re v e < k\ x eps then goto UPDATE;if A: > sigma [order, 0] then goto SPLIT else goto D OU BL E;U P D A T E :if n = 4 A (caution v (xa = a A div = 0)) then gotoD O U B L E ;if e < re then e := re;error : = error + e; eps : = eps e;if eps < 01 x error then eps := 0-1 x error;arts : = ans + int;if div = 0 then goto COMPLETE;

    div : = div 1;xa : = xb; xb : = xs [div];fx [4 ] : = fx [ 0 ] ; / * [ 0 ] : = fs [div];goto NEXT;D O U B L E :comment Double order of formula;for i : = n step 1 until 1 Aofx [2 x /] : = fx [i];n 2 : = n ; : = + n ; w : = 0-5 x m;order : = order + 1;: = e; intprev := int;

    if eprev < re then eprev := re;if n > maxrule then quadrule;/ : = 2 ;g o t o A G A I N ;

    S P L I T :comment Split current subinterval unless simple errorestimate acceptable and consider left half;e := 2 x h x (Jmax fmiri);if e < re v e < k\ x eps thenbegin//if := h x (fmax + fmiri);goto UPDATEend;if /i < A/M//J then go to FA IL ;

    xs [div] : = JCZ>; x6 : = xa + h;fs [div] : = fx [ 0 ] ; fx [0 ] : = / * [2] ; A [4] : = / * [ ] ;rf/v : = div + 1;g o t o N E X T ;C O M P L E T E :end of procedure adapquad

    ReferencesBULIRSCH, R., and STOER, J. (1967). Num erical quad rature by extrapo lation, Numer. Math., Vol. 9, pp. 271-278.CLENSHAW, C. W., and CURTIS, A. R. (1960). A method for numerical integration on an autom atic com puter, Numer. Math., Vol. 2, pp.

    197-205.CRANLEY, R., and PATTERSON, T. N. L. (1971). On the automatic numerical evaluation of definite integrals, The Computer Journal, Vol. 14,pp . 189-198.LYNESS, J. N. (1969). The effect of inadequate convergence criteria in automa tic routines, The Computer Journal, Vol. 12, pp. 279-281.O ' H A R A , H., and SMITH, F. J. (1968). Erro r estimation in the Clenshaw-Curtis quad rature formula, Th e Computer Journal, Vol. 11, pp.213-219.O ' H A R A , H., and SMITH, F. J. (1969). The evaluation of definite integrals by interval subdivision, The Computer Journal, Vol. 12, pp . 179-182.OLIVER, J. (1971). A practical strategy for the Clenshaw-Curtis quadra ture meth od, JIMA, Vol. 8, pp. 53-56.PATTERSON, T. N. L. (1968). The optimum addition of points to qua dratu re formulae, Math. Comp., Vol. 22, pp. 847-856.PATTERSON, T. N. L. (1972). Algorithm for the autom atic numerical integration of integrals over a finite interv al, CACM (to appear).

    CorrespondenceTo the EditorTh e Computer JournalSir

    Remarks on 'Faults in functions, in ALGOL and FORTRAN'We agree with I. D. Hill's (1971) analysis of this problem and withhis judgement on the various solutions, but we should like to adda ninth method of reaction when an error is detected in a function.This method combines most of the desirable properties mentionedby Hill.If it is permitted as a side effect to change the values of somevariables in COMMON (FORTRAN) or some global variable(ALGOL), the error can be reported by the function to the callerin this way. The caller can ask whether the function call was success-ful or not by testing the common variable either directly or via anerror message retrieval function.If the function changes common variable not directly but via anerror handling routine, this routine may decide whether this errorshould result in printing a message or terminating the job due tosome error statistics and control variables set by the user.These features have been implemented in MAPLIB (Pee andSchumann, 1970; Schumann, 1972), a data bank of FORTRANfunctions describing material p roperties; here the functions co mpute

    the value of any property according to some arguments (e.g.temperature which may be out of the validity range of the data-functions. A number of routines and a dedicated labelled COMMONare combined in MAPLIB to provide a powerful 'message and erro rcontrol package'. Yours faithfully,E. G. SCHLECHTENDAHL and U. SCHUMANN

    Kernforschungszentrum KarlsruheInstitut fiir ReaktorentwicklungWeberstrasse 575 KarlsruheGermany27 December 1971ReferencesHILL, I. D. (1971). Faults in functions, in ALG OL an d FO RT RA N,Th e Computer Journal, Vol. 14, No. 3, pp. 315-316.PEE, A., and SCHUMANN, U. (1970). An Integrated ProgramLibrary for Material Property Data, Nucl. Eng. Design, Vol. 14,pp . 99-103.SCHUMANN, U. (1972). MAPLIBA Data Bank of FORT RA N-Functions describing Material Properties, to be published inSoftware Practice and Experience.

    Volume 15 Numb er 2 147