       Re: Mathematica Weirdness

• To: mathgroup at smc.vnet.net
• Subject: [mg116689] Re: Mathematica Weirdness
• From: Christopher Henrich <chenrich at monmouth.com>
• Date: Thu, 24 Feb 2011 06:21:36 -0500 (EST)
• References: <ik2nab\$9kk\$1@smc.vnet.net>

```In article <ik2nab\$9kk\$1 at smc.vnet.net>,
Steve Heston <sheston at rhsmith.umd.edu> 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-Erfi).) 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
good.

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 monmouth.com
http://www.mathinteract.com
"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