0
$\begingroup$

From previous threads I have read on the subject, it seems that Mathematica is known to simplify expressions to varying degrees depending on alphabetical order of chosen variable names. But none of the threads reported functionally different answers. In my case, when using a variable name alphabetically before the integration variable "r", the resulting expression is only defined on part of the domain!

Version info: "11.1.1 for Microsoft Windows (64-bit) (April 18, 2017)"

Is this a bug, or am I missing somthing?

Code starts with global assumptions:

$Assumptions = d > 0 && s > 0 && q > 0

Option 1

Integrate[(r^2*Sin[\[Theta]])/(r^2 + q^2 + 2*r*q*Cos[\[Theta]]),
    {r, 0, d}, {\[Theta], 0, Pi}]

giving

ConditionalExpression[(2*q*(d - q*ArcTanh[q/d]) - d^2*Log[-1 + (2*d)/(d + q)])/(2*q), d >= q]

vs Option 2

Integrate[(r^2*Sin[\[Theta]])/(r^2 + s^2 + 2*r*s*Cos[\[Theta]]), 
    {r, 0, d}, {\[Theta], 0, Pi}]

giving

d + ((d^2 - s^2)*Log[(d + s)^2/(d - s)^2])/(4*s)

Edit: Nasser's answer below solves the problem of discrepancy. But I think MMA should provide another answer for the rest of the domain (d<s or d<w). The plot in the attached image can illustrate.

Plot showing function for the left out domain

$\endgroup$
3
  • $\begingroup$ you should indicate which version number and which OS. No issue on V 12.1 on windows. Screen shot !Mathematica graphics $\endgroup$ – Nasser Jun 8 '20 at 13:45
  • $\begingroup$ apologies. Added it now. Looking at your screenshot, it seems your version picks Option 1 at all names. It's not obvious to me why this integral should only be valid on the limited domain. My guess is that MMA is unable to open the Log[x^2] as 2 Log[Abs[x]], so it instead just ends up doing 2 Log[x] with x>0, whereas it should clearly be the former. $\endgroup$ – aggna Jun 8 '20 at 14:12
  • $\begingroup$ Accepted Nasser's answer for now since it answers my original question about getting different outputs. Will update if I understand in which situations Mathematica picks a branch and gives ConditionalExpression vs in situations in which it outputs a piecewise function with expressions for each branch. $\endgroup$ – aggna Jun 9 '20 at 7:04
0
$\begingroup$

Version info: "11.1.1 for Microsoft Windows (64-bit) (April 18, 2017)"

This looks like something already fixed

V 11

enter image description here

V 12.1

enter image description here

$\endgroup$
0
$\begingroup$

In version 12 it will give you both branches if you ask for them.

$Assumptions = d > 0 && s > d

Integrate[(r^2*Sin[θ])/(r^2 + s^2 + 2*r*s*Cos[θ]), {r, 0, d}, {θ, 0, Pi}]
(*(d^2/s - s) ArcTanh[d/s] + d*)

or

$Assumptions = s > 0 && d > s

Integrate[(r^2*Sin[θ])/(r^2 + s^2 + 2*r*s*Cos[θ]), {r, 0, d}, {θ, 0, Pi}]
(*(d^2/s - s) ArcTanh[s/d] + d*)

With this version, the behavior is the same whether you use q or s.

Mathematica normally gives one answer for one set of conditions by default, but you can specify different conditions to get the result for those conditions if you want.

$\endgroup$
1
  • $\begingroup$ There are times when Mathematica automatically gives me a piecewise function for both branches, at least on v11 that I have. I will look into getting v12 once I look into the backward compatibility for all my current code. $\endgroup$ – aggna Jun 9 '20 at 7:03

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.