       Re: Nested numerical integral - speed: Is it suppose to be so slow?

• To: mathgroup at smc.vnet.net
• Subject: [mg127650] Re: Nested numerical integral - speed: Is it suppose to be so slow?
• From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
• Date: Sat, 11 Aug 2012 04:31:12 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net

```hello.

Newbie here, working with Mathematica 8 on a Windows 7 64-bit system, Intel core i7-2600 @3.4Ghz and 16 GB of RAM. I'm doing a relatively simple double numerical integration of a function composed of trapezoids, but was surprised to see that the computation time was relatively high. The calculation that I need takes about 13 seconds as you can see below, and I need to evaluate it over many different parameters. Is there a way to significantly increase the speed of this execution?

Code:

In:= trap[t_,t1_,t2_,a_]:=Piecewise[{{0,t<0||t>=t1+t2},{a t,t>=
0&&t<t1},{a t1,t>=t1&&t<t2},{a (-t+t1+t2),t>=t2&&t<t1+t2}}]
In:= Ga[t_,t1_,t2_,a_,\[CapitalDelta]_]:=trap[t,t1,t2,a]-trap[t-2 \[CapitalDelta],t1,t2,a]
In:= Fa[t_?NumericQ,g_,a_,\[CapitalDelta]_,\[Delta]_]:=NIntegrate[Ga[u,g/a,\[Delta]-g/a,a,\[CapitalDelta]],{u,0,t}]
In:= ba[g_,a_,\[CapitalDelta]_,\[Delta]_]:=(2.675222/10)^2 NIntegrate[Fa[x,g,a,\[CapitalDelta],\[Delta]]^2,{x,0,\[Delta]+2 \[CapitalDelta]}]
In:= Timing[ba[5.5,100000,12,0.25]]
Out= {13.150999999999996,3.234694880849849}

Sune

Hi, Sune,

Judging from messages I guess, there is a kind of divergence somewhere in the integration domain or something resembling. It can be coped with by fixing the working precision. What else one can do is to parallelize the process. Just as  an idea:

m = 4;
f[g_, a_, \[CapitalDelta]_, \[Delta]_] :=
Module[{v, u, aa, gg, t, t1, t2, deltaL, delta},
trap[t_, t1_, t2_, aa_] :=
Piecewise[{{0, t < 0 || t >= t1 + t2}, {aa t,
t >= 0 && t < t1}, {aa t1,
t >= t1 && t < t2}, {a (-t + t1 + t2),
t >= t2 && t < t1 + t2}}];
Ga[t_, t1_, t2_, aa_, deltaL_] :=
trap[t, t1, t2, aa] - trap[t - 2 deltaL, t1, t2, aa];
Fa[t_?NumericQ, gg_, aa_, deltaL_, delta_] :=
NIntegrate[Ga[u, gg/aa, delta - gg/aa, aa, deltaL], {u, 0, t},
WorkingPrecision -> 5];
(2.675222/10)^2*
Total@ParallelTable[
NIntegrate[
Fa[x, gg, aa, deltaL, delta]^2 /. {gg -> g, aa -> a,
deltaL -> \[CapitalDelta],
delta -> \[Delta]}, {x, (\[Delta] + 2 \[CapitalDelta])/
m i, (\[Delta] + 2 \[CapitalDelta])/m (i + 1)},
WorkingPrecision -> 5], {i, 0, m - 1}]
];

AbsoluteTiming[f[5.5, 100000, 12, 0.25]]

{1.2031435, 3.2305}

where m=4 is the number of kernels on my machine. I did it a bit clumsy, for sure you will do better.

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu

```

• Prev by Date: Re: Simplify Binomial
• Next by Date: compact notation for NonCommutativeMultiply that supports cut and paste
• Previous by thread: Re: Nested numerical integral - speed: Is it suppose to be so slow?
• Next by thread: How to increase evaluation speed for nested numerical integration