2
$\begingroup$

I wonder why I can not have a correct integration form on Mathematica with some indexed variables.

Indeed, when I write :

Integrate[r/Subscript[r, L], {r, 0, Subscript[r, L]}]

I have the following result :

enter image description here

However, when I write :

Integrate[r/Subscript[q, L], {r, 0, Subscript[q, L]}]

I obtain the expected (computed) expression :

enter image description here

Could you explain me where is my error ? and how can I have the expected result with first expression ?

Best,

$\endgroup$
2
  • $\begingroup$ @DanielHuber That's not quite the case, though close. In[79]:= Integrate[q*Subscript[r, n], {Subscript[r, n], 0, q}] Out[79]= q^3/2. The issue with the one in this post is that r is the integration variable, and the integrand contains Subscript[r, L] which is viewed as an unknown function of r. So Integrate is flummoxed. $\endgroup$ May 17, 2023 at 20:07
  • $\begingroup$ Ok, thanks for this remark. But is it possible to prevent the problem ? I would like to use rL as a variable in order to produce more clear formula, rather than using another variable name. To summarize, is-it possible to constrain Mathematica to consider rL not as an unknown function but as a parameter independant from r ? $\endgroup$ May 17, 2023 at 20:10

1 Answer 1

3
$\begingroup$

One idea is to create an environment where subscripts are rendered inert, and then the expression is evaluated. For example:

SetAttributes[InactivatedSubscripts,HoldAll];

InactivatedSubscripts[expr_]:=Block[{CompressedData},
    With[{h=Hold[expr]/.s_Subscript:>RuleCondition@CompressedData[Compress@s]},
        ReleaseHold[h]
    ]
]

Then:

InactivatedSubscripts[
    Integrate[r/Subscript[r,L],{r,0,Subscript[r,L]}]
]

Subscript[r, L]/2

$\endgroup$

Your Answer

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

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