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

• To: mathgroup at smc.vnet.net
• Subject: [mg127644] Re: Nested numerical integral - speed: Is it suppose to be
• From: Bob Hanlon <hanlonr357 at gmail.com>
• Date: Fri, 10 Aug 2012 02:43:21 -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
• References: <20120809075343.71F12664F@smc.vnet.net>

```You should get a slight (>10%) improvement if you rewrite the
definition of trap to

trap[t_, t1_, t2_, a_] = Piecewise[{
{a t, 0 <= t < t1},
{a t1, t1 <= t < t2},
{a (-t + t1 + t2), t2 <= t < t1 + t2}},
0];

Bob Hanlon

On Thu, Aug 9, 2012 at 3:53 AM, Sune <sunenj at gmail.com> wrote:
> 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[19]:= 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[20]:= Ga[t_,t1_,t2_,a_,\[CapitalDelta]_]:=trap[t,t1,t2,a]-trap[t-2\[CapitalDelta],t1,t2,a]
> In[21]:= Fa[t_?NumericQ,g_,a_,\[CapitalDelta]_,\[Delta]_]:=NIntegrate[Ga[u,g/a,\[Delta]-g/a,a,\[CapitalDelta]],{u,0,t}]
> In[22]:= ba[g_,a_,\[CapitalDelta]_,\[Delta]_]:=(2.675222/10)^2 NIntegrate[Fa[x,g,a,\[CapitalDelta],\[Delta]]^2,{x,0,\[Delta]+2 \[CapitalDelta]}]
> In[23]:= Timing[ba[5.5,100000,12,0.25]]
> Out[23]= {13.150999999999996,3.234694880849849}
>
> Sune
>

```

• Prev by Date: Re: Nested numerical integral - speed: Is it suppose to be so slow?
• Next by Date: Re: Nested numerical integral - speed: Is it suppose to be so slow?
• Previous by thread: Re: Nested numerical integral - speed: Is it suppose to be so slow?
• Next by thread: Re: Nested numerical integral - speed: Is it suppose to be so slow?