Re: compile a numerical integral
- To: mathgroup at smc.vnet.net
- Subject: [mg124596] Re: compile a numerical integral
- From: Gabriel Landi <gtlandi at gmail.com>
- Date: Thu, 26 Jan 2012 03:25:04 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jflvvs$jr4$1@smc.vnet.net> <201201251205.HAA06021@smc.vnet.net>
You may profit considerably from "SymbolicProcessing"->0. For instance
In[106]:= tab1 = Table[
NIntegrate[x^n Exp[x], {x, -1, 1}], {n, 2, 40, 2}]; // AbsoluteTiming
Out[106]= {0.282903, Null}
In[116]:= tab2 = Table[NIntegrate[x^n Exp[x], {x, -1, 1}, Method -> {"GlobalAdaptive"} ], {n, 2, 40, 2}]; // AbsoluteTiming
Out[116]= {0.273898, Null}
In[117]:= tab3 = Table[
NIntegrate[x^n Exp[x], {x, -1, 1},
Method -> {"GlobalAdaptive", "SymbolicProcessing" -> 0}
], {n, 2, 40, 2}]; // AbsoluteTiming
Out[117]= {0.069791, Null}
And
In[114]:= tab1 - tab2
Out[114]= {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}
In[115]:= tab1 - tab3
Out[115]= {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}
Best regards,
Gabriel
On Jan 25, 2012, at 10:05 AM, Oleksandr Rasputinov wrote:
> On Tue, 24 Jan 2012 10:09:00 -0000, Ruth Lazkoz S=E1ez <ruth.lazkoz at ehu.es>
> wrote:
>
>> Hi wise people,
>>
>> I am working to make a code faster using compile and failed at the very
>> beginning.
>> Is there a way to make a version that works?
>>
>> f=Compile[{u},NIntegrate[x*u,{x,0.,#}]&/@{1,2,3}]
>>
>> Best,
>>
>> Ruth Lazkoz
>>
>
> Sorry to disappoint, but no. NIntegrate cannot be compiled and, even if it
> could, it wouldn't provide any meaningful performance improvement
> (although sometimes the integrand can be compiled; if this is likely to be
> beneficial it will be done automatically, but you can try it manually
> using the option Compiled->True). However, one can often benefit by
> changing the Method option appropriately (see
> tutorial/NIntegrateIntegrationRules), although this can be quite involved
> and is obviously not a panacea. It is worth persisting, however: in an
> example from my own work, optimizing the Method yielded a fourfold
> reduction in calculation time versus the default setting when evaluating
> some complicated projection integrals, and I was only able to improve on
> this slightly (by another 40% or so) by pre-calculating the integration
> bounds analytically for special cases of the integrand instead of letting
> NIntegrate find the bounds itself.
>
- References:
- Re: compile a numerical integral
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
- Re: compile a numerical integral