MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica Weirdness

In article <ik2nab$9kk$1 at>,
 Steve Heston <sheston at> wrote:

> My question is why I get a negative integral of a positive 
> function?
> Integrate[1000000*Exp[x^2-12*x]*x^14,{x,0,1}]//N
> Integrate[1000000*Exp[x^2-12*x]*x^14,{x,0.,1}]//N
> NIntegrate[1000000*Exp[x^2-12*x]*x^14,{x,0,1}]
> The first line gives a negative answer, while the second two lines give 
> identical positive answers.  Something is strange here.

If you strip "//N" from the first line, you get an expression with three 
terms (I am counting as "one term" a product that involves 
(Erfi[5]-Erfi[6]).) Two of these terms are much larger than the third, 
with opposite signs and nearly equal magnitudes. Their sum seems to be 
of opposite sign to the other term, and *very* nearly equal magnitudes. 
In short there is some massive cancellation going on. I think the number 
of extra digits of precision carried along in the numerical evaluation 
implied by "//N" was not enough to get a good result.

I do not know why the second line came out differently. I suspect that 
Mathematica used a different strategy for working out the analytical 
form of the integration, because of the machine-precision number "0." .

The third line does not attempt to find an analytical form for the 
integral, but applies numerical integration methods from the outset. A 
plot of the integrand shows that it is not very "pathological" in the 
sense of having a tall narrow spike, so the numerical result is probably 

The online documentation of N and NIntegrate is helpful for giving one a 
sense of the limitations of the numerical accuracy of these functions, 
and for suggestions of how to experiment with the precision of their 
internal operations.

Christopher J. Henrich
chenrich at
"A bad analogy is like a leaky screwdriver." -- Boon

  • Prev by Date: Re: outputting C code
  • Next by Date: Re: Emacs with Mathematica
  • Previous by thread: Re: Mathematica Weirdness
  • Next by thread: Re: Mathematica Weirdness