Message Boards Message Boards

0
|
4356 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Speed of Multiple Integrals

Posted 10 years ago

I have been using Mathematica 10 for a while now and noticed that the time required for multiple integrals seems to be excessive.

In[2]:= Timing[
 Integrate[(x^2 + y^2)/a, {y, 0,  a / Sqrt[2]}, {x, y, 
     Sqrt[a^2 - y^2]}] // PowerExpand // Simplify]

Out[2]= {21.903075, (a^3 \[Pi])/16}

In[3]:= Timing[
 Integrate[
    Integrate[(x^2 + y^2)/a, {x, y, Sqrt[a^2 - y^2]}], {y, 0, 
     a / Sqrt[2]}] // PowerExpand // Simplify]

Out[3]= {1.542915, (a^3 \[Pi])/16}

In[4]:= Timing[
 g[y_] = Integrate[Integrate[(x^2 + y^2)/a, {x, y, Sqrt[a^2 - y^2]}], 
   y]; (g[a/Sqrt[2]] - g[0]) // PowerExpand // Simplify]

Out[4]= {0.048080, (a^3 \[Pi])/16}

Apparently, using one call to integrate a double integral takes 14 times as long as calling integrate twice, and integrating to a function and subsequently evaluating that function at the limits is 32 times faster than giving the limits to Integrate.

Seems like there is a bug there.

POSTED BY: dave salmon
2 Replies
Posted 10 years ago

I ran it three times as you suggested, and indeed the first two take about the same time now. However, the third method (closed form with evaluation at the limits) remains about 50 times faster than providing the limits to Integrate (1.5 seconds when limits are given, 0.03 second when the function is generated and evaluated at the limits).

POSTED BY: dave salmon
Posted 10 years ago

If you reverse the order of the first two (and start with a fresh kernel), then the first one will take longer in about the same timing. Also if you run both of the first two again (without restarting the kernel), then they complete in about the same amount of time. And running it a second time improves the timing for all 3.

Timing[Integrate[
    Integrate[(x^2 + y^2)/a, {x, y, Sqrt[a^2 - y^2]}], {y, 0, 
     a/Sqrt[2]}] // PowerExpand // Simplify]
Timing[Integrate[(x^2 + y^2)/a, {y, 0, a/Sqrt[2]}, {x, y, 
     Sqrt[a^2 - y^2]}] // PowerExpand // Simplify]
Timing[g[y_] = 
  Integrate[Integrate[(x^2 + y^2)/a, {x, y, Sqrt[a^2 - y^2]}], 
   y]; (g[a/Sqrt[2]] - g[0]) // PowerExpand // Simplify]
POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract