Re: NIntegrate Problem
- To: mathgroup at smc.vnet.net
- Subject: [mg94653] Re: NIntegrate Problem
- From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
- Date: Fri, 19 Dec 2008 07:22:50 -0500 (EST)
- Organization: University System of Maryland
- References: <giapeb$9e9$1@smc.vnet.net> <gidf8v$cu$1@smc.vnet.net>
Anton, The SymbolicProcessing->0 is a great suggestion. I had incorrectly thought that NIntegrate would just do numerical integration. Guess I was wrong. Your suggestion makes a huge difference in what I am doing. Thanks again. Kevin antononcube at gmail.com wrote: > Because NIntegrate evaluates the integrands before starting the actual > integration, you need to define W with the signature W[t_?NumericQ, v_? > NumericQ]. > > As for the speed of integration, you can do several things. You can > change the precision goal to something smaller than the default (which > is 6 for machine working precision.) For this integral it seems that > skipping the symbolic preprocessing, with Method -> {Automatic, > SymbolicProcessing -> 0}, gives significant speed-up. > > > In[56]:= Clear[W, G2] > 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[E^(-(v^2/8)) W[t, v], {v, -7., 7.}] > > In[59]:= G2[0.0] // Timing > > Out[59]= {0.325792, 56.8889} > > > In[60]:= Clear[W, G2] > 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.}, > Method -> {Automatic, SymbolicProcessing -> 0}]]^2 > G2[t_] := NIntegrate[E^(-(v^2/8)) W[t, v], {v, -7., 7.}] > > In[63]:= G2[0.0] // Timing > > Out[63]= {0.055748, 56.8889} > > > Anton Antonov > Wolfram Research, Inc. > > > On Dec 17, 6:56 am, "Kevin J. McCann" <Kevin.McC... at umbc.edu> 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 > >