Re: NIntegrate - Gaussian quadrature more exact than thought

*To*: mathgroup at smc.vnet.net*Subject*: [mg73987] Re: NIntegrate - Gaussian quadrature more exact than thought*From*: Peter Pein <petsie at dordos.net>*Date*: Sun, 4 Mar 2007 02:04:07 -0500 (EST)*References*: <es6dmv$s61$1@smc.vnet.net>

janos schrieb: > NIntegrate[x^4, {x, 0, 1}, Method->GaussKronrod, GaussPoints->2] > > gives 0.2, the exact result, although the Gauss quadrature should be > inexact on a polynomial of degree 2n+2 where n is the number of > GaussPoints. More exactly, we expected the same results as here: > > << NumericalMath`GaussianQuadrature` > gw = GaussianQuadratureWeights[2, 0, 1] > f[{x_, y_}] := x^4 y > Total[f /@ gw] > 0.194444 > > This is inexact, OK. > > Why is NIntegrate so good? > Something I may have missed. > > Thank you for your help. > > Janos > > Hi Janos, obviously a subdivision of the interval takes place: Length[xvals = Reap[result = NIntegrate[x^4, {x, 0, 1}, Method -> GaussKronrod, GaussPoints -> 2, EvaluationMonitor :> Sow[x]]][[2,1]]] result --> 155 0.2 With Listplot[xvals] you can see, where the evaluations have been done. At least a warning can be forced by additionally setting MaxRecursion to 0: Length[xvals = Reap[result = NIntegrate[x^4, {x, 0, 1}, Method -> GaussKronrod, GaussPoints -> 2, MaxRecursion -> 0, EvaluationMonitor :> Sow[x]]][[2,1]]] Abs[result - 1/5] NIntegrate::ncvb : <NIntegrate failed to converge to prescribed accuracy after 1 recursive bisections in x near x = 0.25`. More... --> 15 0. Peter