Re: Problem with an integral

*To*: mathgroup at smc.vnet.net*Subject*: [mg95611] Re: Problem with an integral*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Thu, 22 Jan 2009 07:04:46 -0500 (EST)

On 1/21/09 at 7:02 AM, jepessen at gmail.com (Jepessen) wrote: >I'm working with a little problem in Mathematica 7.0.0. I want to >integrate this function >fun = x^(n + 1)*E^(-x + (I*k)/x) >Assuming that both n and k are greater than zero, I write >integral = FullSimplify[Assuming[{k > 0, n > 0}, Integrate[fun, {x, >0, \[Infinity]}]]] >And I obtain a symbolic result. But, when I want to put some >specific value, like this >integral /. {n -> 1, k -> 1} >I obtain always ComplexInfinity, and/or other errors. So, I've tried >to evaluate numerically the integral for the same specific values, >in this way >NIntegrate[Evaluate[fun /. {n -> 1, k -> 1}], {x, 0, \[Infinity]}] >And I obtain a finite numeric result. So, there's some error in >symbolic computation, or I miss something when I try to integrate >the formula? Neither. This issue arises due to the way Mathematica does evaluations. Mathematica first does replacements indicated then evaluates the result. So, (x - 2 x +1)/(x - 1)/.x->1 will evaluate as (1 - 2 + 1)/(1 - 1) = 0/0 and generate an error. That is Mathematica does not simplify (x - 2 x +1)/(x - 1) to x - 1 and then do the substitution. Even using FullSimplify before doing the substitution will not always resolve the problem particularly for a complex result returned by Integrate. For a complex integral, FullSimplify may not be able to simplify the result from Integrate to successfully remove singularities. Nor does Mathematica do anything to improve numeric stability of the result. These are two of the reasons why NIntegrate should always be used in preference to N[Integrate[... when a numerical result for an integral is desired.