When I try to calculate the following integral:
Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π},
{θ, 0, π},
{αp, 0, 2 π},
{αr, 0, 2 π},
{pr, 0, lp},
{r, 0, lr}
]
Mathematica returns:
$$ \frac{16}{9} \pi^2 l_p^3 l_r^3 $$
which is what I expected. However, if I calculate the same integral but adding some assumptions:
Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π},
{θ, 0, π},
{αp, 0, 2 π},
{αr, 0, 2 π},
{pr, 0, lp},
{r, 0, lr},
Assumptions -> Element[{lr, lp}, Reals] && lr > 0 && lp > 0
]
Mathematica returns:
$$ \frac{32}{9} \pi^2 l_p^3 l_r^3 $$
If I then try and calculate the integral numerically (by setting lr=lp=1):
NIntegrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π},
{θ, 0, π},
{αp, 0, 2 π},
{αr, 0, 2 π},
{pr, 0, 1},
{r, 0, 1}
]
Mathematica returns: 35.0918
Which is close to
N[(32 π^2)/9]
Then I try to calculate the integral part by part using Mathematica:
Integrate[r^2, {r, 0, lr}]
Integrate[pr^2, {pr, 0, lp}]
Integrate[Abs[Cos[θ]], {θ, 0, π}]
Integrate[
Abs[Sin[αr - αp]],
{αp, 0, 2 π},
{αr, 0, 2 π}
]
Integrate[1, {ϕ, 0, 2 π}]
and I get: $\frac{l_r^3}{3}$, $\frac{l_p^3}{3}$, 2, $8 \pi$ and $2 \pi$ respectively, which will multiply to get $\frac{32}{9} \pi^2 l_p^3 l_r^3$.
Edit
I managed to pinpoint closer to the part of the integral which is exhibiting this weird behaviour:
Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{αp, 0, 2 π},
{pr, 0, lp},
{αr, 0, 2 π},
{r, 0, lr},
Assumptions -> Element[{lr, lp}, Reals] && lr > 0 && lp > 0
]
Without Assumptions
, it gives $\frac{4}{9} \pi l_p^3 l_r^3 |\cos \theta|$, with Assumptions
, it gives $\frac{8}{9} \pi l_p^3 l_r^3 |\cos \theta|$. Using NIntegrate
, it gives a result close to $\frac{8}{9} \pi l_p^3 l_r^3 |\cos \theta|$.
Here's a related but simpler problem that shows the same effect:
{Integrate[r Abs[Sin[αr - αp]], {αp, 0, 2 π}, {αr, 0, 2 π}, {r, 0, lr},
Assumptions -> lr > 0],
Integrate[r Abs[Sin[αr - αp]], {αp, 0, 2 π}, {αr, 0, 2 π}, {r, 0, lr}]}
{4 lr^2 π, 2 lr^2 π}
Questions: Does adding these assumptions change the true values of the integrals? In the first integral, if both are not correct, which of the two results is correct? Should this question be tagged with "bugs"?