3
$\begingroup$

I'm Trying to use Mathematica to symbolically integrate a function with respect to x, y, and z.

For some reason, this computation either takes about, 60s and returns the input, or takes many hours and doesn't seem to finish. here is a screenshot of the problem. This is an attempt to integrate the gravitational potential equation over x, y, and z. The constants have been pulled out of the integration in order to try and reduce computation error or time.

integration of gravitational force

as you can see, at this moment in time, mathematica has been working for over 20,000 seconds (running about 30% on i7 @ 2.8ghz.

I feel like perhaps there is an error in my formatting, because i've run into many problems attempting to perform similar integration. I've used assumptions in past attempts, but they've haven't proved useful.

any suggestions?

$\endgroup$
9
  • $\begingroup$ It will likely help to specify Assumptions->{L>0,W>0,a>0,b>a} etc (or whatever they should be ) $\endgroup$
    – george2079
    Jun 10, 2014 at 20:36
  • $\begingroup$ You can use Integrate[1/Sqrt[x^2 + y^2 + z^2], x, y, z], as this does quickly give an answer. Then fill in the bounds manually. $\endgroup$ Jun 10, 2014 at 20:37
  • 3
    $\begingroup$ One thing that sometimes "works" is to assign to the positive parameters various mathematica constants. Could in this case do, say,Integrate[-1/Sqrt[x^2 + y^2 + z^2], {z, Catalan, EulerGamma}, {x, 0, Khinchin}, {y, 0, Glaisher}] // AbsoluteTiming. After which you can substitute with {Catalan->a, EulerGamma->b, Khinchin->L/2,Glaisher->W/2}. $\endgroup$ Jun 10, 2014 at 22:21
  • 1
    $\begingroup$ Interesting trick! - it is marginally faster in this case. You need to be wary of conditions on the parameters that might get missed by feeding specific values though. $\endgroup$
    – george2079
    Jun 11, 2014 at 14:58
  • 1
    $\begingroup$ What is the ShowProgress function code? It very interesting. $\endgroup$ Mar 29, 2018 at 18:36

2 Answers 2

6
$\begingroup$

since I claimed it worked here is what i did:

 xy = Integrate[ -1/Sqrt[x^2 + y^2 + z^2] , {x, 0, L/2}, {y, 0, W/2},
    Assumptions -> {L > 0, W > 0 , z > 0, a > 0, b > a}];
 Integrate[ xy , {z, a, b}, 
        Assumptions -> {L > 0, W > 0 , z > 0, a > 0, b > a}]

result a page full of Logs and ArcTans and a few ConditionalExpressions

The full triple integral is taking way longer than the two stage approach for some reason.

Edit.. finally finished ( I also changed the integration order and added b>0)

 Integrate[ -1/Sqrt[x^2 + y^2 + z^2] , {z, a, b},
       {x, 0, L/2}, {y, 0, W/2},
         Assumptions -> {L > 0, W > 0 , z > 0, a > 0, b > 0 , b > a}] // AbsoluteTiming

enter image description here

per Michael's comment after FullSimplify

enter image description here

$\endgroup$
2
  • $\begingroup$ hmm, DO you know where the imaginary component comes from? $\endgroup$ Jun 10, 2014 at 21:51
  • $\begingroup$ @EverettKnag From the integration algorithm. If you do FullSimplify[expr, {L > 0, W > 0, a > 0, b > 0, b > a}], the imaginary Is go away. $\endgroup$
    – Michael E2
    Jun 11, 2014 at 3:18
5
$\begingroup$

Using the Rubi integration package for Mathematica (http://www.apmaths.uwo.ca/~arich/), this takes under three seconds on a late-2014 MacBook Pro, requires no assumptions, and gives a relatively clean result:

x1 = Int[-1/Sqrt[x^2 + y^2 + z^2], x];
x2 = (x1 /. x -> L/2) - (x1 /. x -> 0);
y1 = Int[x2, y];
y2 = (y1 /. y -> W/2) - (y1 /. y -> 0);
z1 = Int[y2, z];
z2 = (z1 /. z -> b) - (z1 /. z -> a)

[Rubi doesn't do definite integrals, which is why I had to add separate statements (x2, y2, and z2) to compute those.]

enter image description here

AbsoluteTiming for the entire cell was 2.4 s.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.