Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8177
| From | Gabriel Landi <gtlandi@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: compile a numerical integral |
| Date | 2012-01-26 08:25 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jfr2mi$nb4$1@smc.vnet.net> (permalink) |
| 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@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.
>
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
compile a numerical integral Ruth Lazkoz Sáez <ruth.lazkoz@ehu.es> - 2012-01-24 10:09 +0000 Re: compile a numerical integral psycho_dad <s.nesseris@gmail.com> - 2012-01-25 12:01 +0000 Re: compile a numerical integral danl@wolfram.com - 2012-01-25 12:03 +0000 Re: compile a numerical integral "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2012-01-25 12:09 +0000 Re: compile a numerical integral Gabriel Landi <gtlandi@gmail.com> - 2012-01-26 08:25 +0000
csiph-web