Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11302

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

From Sune Nørhøj Jespersen <sunenj@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Nested numerical integral - speed: Is it suppose to be so slow?
Date 2012-08-10 06:43 +0000
Message-ID <k02ai3$2t6$1@smc.vnet.net> (permalink)
References <20120809075343.71F12664F@smc.vnet.net> <88608B12-7C77-44FE-8D4C-1D6AFBF8F474@mit.edu>
Organization Time-Warner Telecom

Show all headers | View raw


Hi Craig and Bob.

Thank you very much for your replies. (Your answers are not appearing in the
group, so I hope I'm not doing anything wrong by e-mailing you directly)
Craigs suggestion resulted in roughly a factor of 10 speed up, so pretty
substantial! (I did try symbolic implementation at some point, but must've
done something wrong). With both of your suggestion (included below for
completeness), the execution time is now 0.7s, versus 13 seconds for the old
code.
Craig, t1 and t2 were replaced by combinations of g and a in the definition
of Fa.
Sune

The code is
In[17]:= trap[t_, t1_, t2_, a_] :=
 Piecewise[{{a t, 0 < t < t1}, {a t1, t1 < t < t2}, {a (t1 - t + t2),
    t2 < t < t2 + t1}}, 0]

In[18]:= Ga[t_, t1_, t2_, a_, \[CapitalDelta]_] :=
 trap[t, t1, t2, a] - trap[t - 2 \[CapitalDelta], t1, t2, a]

In[19]:= Fa[t_, g_, a_, \[CapitalDelta]_, \[Delta]_] :=
 Integrate[Ga[u, g/a, \[Delta] - g/a, a, \[CapitalDelta]], {u, 0, t},
  Assumptions -> Element[{t, g, a, \[Delta], \[CapitalDelta]}, Reals]]

In[20]:= ba[g_,
  a_, \[CapitalDelta]_, \[Delta]_] := (2.675222/10)^2 Integrate[
   Fa[x, g, a, \[CapitalDelta], \[Delta]]^2, {x,
    0, \[Delta] + 2 \[CapitalDelta]},
   Assumptions -> Element[{g, a, \[Delta], \[CapitalDelta]}, Reals]]

In[21]:= Timing[ba[5.5, 100000, 12, 0.25]]

Out[21]= {0.702, 3.23471}

--
Sune N=F8rh=F8j Jespersen
CFIN/MindLab and Dept. of Physics and Astronomy
Aarhus Universitet
N=F8rrebrogade 44, bygn 10G, 5. sal
8000 =C5rhus C
Denmark
Phone: +45 78463334
Cell: +45 60896642
E-mail: sune@cfin.au.dk
Web: http://www.cfin.au.dk/~sune


-----Original Message-----
From: W Craig Carter [mailto:ccarter@MIT.EDU]
Sent: 9. august 2012 12:26
To: Sune
Cc: mathgroup@smc.vnet.net
Subject: Re: Nested numerical integral - speed: Is it suppose to
be so slow?

Hello Sune,
I believe you can work symbolically:

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}}]

tplus = Integrate[trap[t, t1, t2, a], {u, 0, t},
  Assumptions -> Element[{g, a, \[Delta], \[CapitalDelta], t}, Reals]]

tminus = Integrate[trap[t - 2 \[CapitalDelta], t1, t2, a], {u, 0, t},
  Assumptions -> Element[{g, a, \[Delta], \[CapitalDelta], t}, Reals]]

inttminus =
 Integrate[tminus, {u, 0, t},
  Assumptions -> Element[{g, a, \[Delta], \[CapitalDelta], t}, Reals]]

inttplus =
 Integrate[tplus, {u, 0, t},
  Assumptions -> Element[{g, a, \[Delta], \[CapitalDelta], t}, Reals]]

baSym = (2.675222/10)^2 ( inttplus - inttminus)


baSym /. {t -> 5.5,
  a -> 100000, \[CapitalDelta] -> 12, \[Delta] -> 0.25} (*the result depends
on t1 and t2 which are undefined?*)



W Craig Carter
Professor of Materials Science, MIT



On Aug 9, , at Thu Aug 9, 12 @3:53 AM, Sune wrote:

> In[22]:= ba[g_,a_,\[CapitalDelta]_,\[Delta]_]:=(2.675222/10)^2
NIntegrate[Fa[x,g,a,\[CapitalDelta],\[Delta]]^2,{x,0,\[Delta]+2
\[CapitalDelta]}]


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Nested numerical integral - speed: Is it suppose to be so slow? Sune Nørhøj Jespersen <sunenj@gmail.com> - 2012-08-10 06:43 +0000

csiph-web