MathGroup Archive 2008

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

Search the Archive

Re: NIntegrate Problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94642] Re: [mg94619] NIntegrate Problem
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 18 Dec 2008 07:23:31 -0500 (EST)
  • References: <200812171156.GAA09649@smc.vnet.net>

On 17 Dec 2008, at 20:56, Kevin J. McCann wrote:

> I have the following double integral
>
> W[t_, v_] :=
>  Abs[NIntegrate[
>    E^(-((u^2 + u v)/8.))
>      Sinc[(u + v)/2.] E^(-I (t + 0.5) u) , {u, -5., 5.}]]^2
> G2[t_] := NIntegrate[E^(-(v^2/8)) W[t, v], {v, -7., 7.}]
>
> G2[0.0]
>
> The last part produces this rather strange output, considering that  
> the
> Abs[]^2 should not give out complex numbers.
>
> NIntegrate::inumr: The integrand E^(-0.5 I u-0.125 (<<1>>+<<1>>))
> Sinc[0.5 (u+v)] has evaluated to non-numerical values for all sampling
> points in the region with boundaries {{-5.,5.}}.
>
> NIntegrate::inumr: The integrand E^(-0.5 I u-0.125 (<<1>>-<<1>>))
> Sinc[0.5 (u-v)] has evaluated to non-numerical values for all sampling
> points in the region with boundaries {{-5.,5.}}.
>
> General::stop: "\!\(\*
> StyleBox[\"\\\"Further output of \\\"\", \"MT\"]\)\!\(\* StyleBox[
> RowBox[{\"NIntegrate\", \"::\", \"\\\"inumr\\\"\"}], \"MT\"]\)\!\(\*
> StyleBox[\"\\\" will be suppressed during this calculation.\\\"\",
> \"MT\"]\) "
>
> 56.8889
>
> One other interesting thing is that after all the complaining, it does
> produce an answer. Evaluate of the function W[t,v] above only produces
> real numbers. In addition, the integration is very slow. I got around
> the problem by building a Table of W, using Interpolation, and then
> integrating that - very fast, and no problems.
>
> Any ideas why I would get the above complaints?
>
> Thanks,
>
> Kevin
>


The problem is that  in order to achieve better performance,  
NIntegrate attempts to evaluate the integrands before they assume  
numerical values, so you get error messages, but then it substitutes  
numeric values and gets the right answer anyway, albeit slowly. You  
can prevent this behaviour by restricting the patterns in the  
definition of W to numeric values only:

Clear[W,G]

W[t_?NumericQ, v_?NumericQ] :=
  Abs[NIntegrate[
     E^(-((u^2 + u v)/8.)) Sinc[(u + v)/2.] E^(-I (t + 0.5) u), {u,  
-5., 5.}]]^2
G2[t_] := NIntegrate[EE^(-(v^2/8)) W[t, v], {v, -7., 7.}]

G2[0.0]
56.8889

Andrzej Kozlowski




  • Prev by Date: Re: Re: "The requested evaluator is not currently defined"
  • Next by Date: Re: Need Help
  • Previous by thread: Re: NIntegrate Problem
  • Next by thread: Re: NIntegrate Problem