Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
It will likely help to specify Assumptions->{L>0,W>0,a>0,b>a} etc (or whatever they should be ) – george2079 Jun 10 '14 at 20:36
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. – Jacob Akkerboom Jun 10 '14 at 20:37
Can I fill them in manually? How can I fill in the x-bounds if it has then been integrated dy. Should I do this one step at a time? Is there a reason why adding bounds is so hard for Mathematica? – Everett Knag Jun 10 '14 at 20:42
@JacobAkkerboom I'm not sure what to do with that multiple indefinite either - may be a useful answer if you can show the steps.. – george2079 Jun 10 '14 at 20:49
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}. – Daniel Lichtblau Jun 10 '14 at 22:21
up vote 3 down vote accepted

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

share|improve this answer
hmm, DO you know where the imaginary component comes from? – Everett Knag Jun 10 '14 at 21:51
@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. – Michael E2 Jun 11 '14 at 3:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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