       Re: Mathematica Weirdness

• To: mathgroup at smc.vnet.net
• Subject: [mg116708] Re: Mathematica Weirdness
• From: Daniel Lichtblau <danl at wolfram.com>
• Date: Thu, 24 Feb 2011 06:25:02 -0500 (EST)

```Steve Heston 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.
>
> Steve
>
> Steven L. Heston
> Associate Professor
> Finance Department
> Robert H. Smith School of Business
> 4447 Van Munching Hall Van Munching Hall
> University of Maryland
> College Park, MD 20742-1815
> 301-405-9686 TEL
> 301-405-0359 FAX
> sheston at rhsmith.umd.edu
> http://www.rhsmith.umd.edu

It's cancellation error in machine arithmetic.

Breaking into parts

In:= InputForm[ii = Integrate[1000000*Exp[x^2-12*x]*x^14, {x,0,1}]]
Out//InputForm=
(-78125*(-84400018990*E^25 + 69863114844*E^36 + 413182474389*Sqrt[Pi]*
(Erfi - Erfi)))/(4*E^36)

In:= InputForm[N[ii]]
Out//InputForm= -0.8133035309472584

If instead you numerically evaluate using precision tracking you will
get a positive result.

In:= InputForm[N[ii,20]]
Out//InputForm= 2.74821242373456642759753885810434205331`20.