2
$\begingroup$

I am trying to do a spherical integral in Mathematica:

f[θ_, ϕ_] = (k^4 Cos[θ]^2 Cot[β] Csc[β] Sin[θ]^3 Sin[ϕ]^2)/(
  4 (1 + k Cos[θ]) (1 + k Cos[β] Cos[θ] + k Cos[ϕ] Sin[β] Sin[θ])) + 
  (k^4 Cos[θ] Cos[ϕ] Csc[β] Sin[θ]^4 Sin[ϕ]^2)/(
  4 (1 + k Cos[θ]) (1 + k Cos[β] Cos[θ] + k Cos[ϕ] Sin[β] Sin[θ]))

If I try the following:

Integrate[f[θ, ϕ], {ϕ, 0, 2 π}]

Mathematica does not produce an answer. However, if I try to do an analytical integral like this:

g[θ_] = Integrate[f[θ, ϕ], ϕ]

I get an answer very quickly, and that answer differentiates to the integrand I started with. Now I can evaluate the value of the integral I am trying to find by doing:

g[2 π] - g[0]

My question is twofold:

  1. Why is this happening in Mathematica? I assume it is because the algorithms for finding a definite and indefinite integrals are different.
  2. Is this a valid way of doing the integral in this case (and others)? I am asking because the end result does not agree with a purely numerical integral over the sphere, and this might be the source of error.
$\endgroup$
  • $\begingroup$ "I assume it is because the algorithms for finding a definite and indefinite integrals are different." - yes, it has to worry about branch cuts and such, since Mathematica assumes everything is complex unless told otherwise. You might wish to look up Assuming[]. $\endgroup$ – J. M. is away Aug 17 '17 at 14:06
  • $\begingroup$ Thank you @J.M., I know one needs to use assumptions. For the above integral I have tried: Assumptions -> {k > 0 && k < 1 && [Beta] >= 0 && [Beta] <= [Pi] && [Theta] >= 0 && [Theta] <= [Pi] && k [Element] Reals && [Beta] [Element] Reals && [Theta] [Element] Reals} but it hasn't helped much. $\endgroup$ – Morgan Aug 17 '17 at 14:33
  • $\begingroup$ To simplify matters slightly: if you put in a condition like 0 < k <1, then you don't need to put in k ∈ Reals, since your use of the inequality already imposes that condition. $\endgroup$ – J. M. is away Aug 17 '17 at 14:43
4
$\begingroup$

It seems like you just weren't patient enough. After 12.5 minutes, version 11.1.1 gives me an answer. Not a beautfiul one, but not a ridiculuous one, either. We've made this better in 11.2. It takes it a little over a minute to come up with a simpler answer.

Re 1): It might use different methods for definite and indefinite integration (e.g., residues aren't of much use for indefinite integrals). It could also be that it's checking that the antiderivative is is continuous over the interval of integration / trying to patch pieces together to find a continuous one. Without really going into the guts of Integrate, I couldn't tell you which.

Re 2): Given 1, that's dangerous. Not to claim that Integrate is perfect, but if it could do the integral by a simple application of the fundamental theorem, it probably would have, so you should check such answers carefully.

$\endgroup$
  • $\begingroup$ Great answer, thank you. In fact I realised why this happens in the meantime. But one thing I want to ask you: 11.2? When is it going to be released? $\endgroup$ – Morgan Aug 17 '17 at 22:18
  • 1
    $\begingroup$ For a wonderful explanation for why you sometimes can't say Integrate[f[x],{x,a,b}] = F[b] - F[a] read blog.wolfram.com/2011/11/08/… other issues with integration are discussed at blog.wolfram.com/2011/11/08/… $\endgroup$ – Ted Ersek Aug 17 '17 at 22:29
  • $\begingroup$ Additionally there is also this blog entry by Oleksandr Pavlyk. $\endgroup$ – J. M. is away Aug 17 '17 at 22:40
  • 1
    $\begingroup$ To quote Robert X Cringly: "Real Soon Now', a computer industry expression meaning In this lifetime, maybe`". :) I cannot give any date certain, but we have had a couple of pre-releases to beta testers, and we're fixing some critical bugs discovered in the process. So hopefully in the fairly near future. $\endgroup$ – Itai Seggev Aug 17 '17 at 23:44
  • $\begingroup$ @Itai, I see; 6-8 weeks it is, then… :) $\endgroup$ – J. M. is away Aug 18 '17 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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