I'd like to define a series of variables called $l_1$,$l_2$, etc., in Mathematica, using the "ctrl+_" shortcut. Moreover, I want to use these variables as the controls of a Manipulate[] function so that I can see how an expression is affected by the change of these variables.

Somehow it seems that Manipulate can't take controls containing Subscripts (as far as I remember, I encountered this issue before so I guess this is the case). For example, in the following code, "h" is recognized as a control which is displayed with a different color; on the other hand, the variables containing subscripts won't be recongnized.

   Labeled[ {Subscript[A, 0], Subscript[A, 11], Subscript[A, 2], 
     Subscript[A, 3], Subscript[A, 41], Subscript[A, 5]}, 
    "label is:"], Frame -> True, Axes -> False, AspectRatio -> 1, 
   ImageSize -> Medium]}, {{Subscript[l, 0], 0}, -1, 
  1}, {{Subscript[l, 1], 0.5}, -1, 1}, {{Subscript[l, 2], 0.5}, -1, 
  1}, {{Subscript[l, 3], 0}, -1, 1}, {{Subscript[l, 4], 0.5}, -1, 
  1}, {{Subscript[l, 5], 0.5}, -1, 1}, {{h, 0.5}, -1, 1}]

see the different color of the controls in Manipulate[]

  • 1
    $\begingroup$ Subscripted variables lead often to trouble. Avoid them, use indexed variables. You can still, after the calculations done, change them to subscripted. $\endgroup$ Jun 18 at 10:27
  • $\begingroup$ @DanielHuber this is what I have observed, too. I attempted to use subscripts because I have complex internal expressions which I want to see in a neater way, and I thought that there might be some solutions that I'm not aware of. I'm kind of surprised that this simple task can't be done in Mathematica. $\endgroup$
    – larry
    Jun 18 at 12:39
  • $\begingroup$ @larry, I don't understand the example you have provided. You have $l_i$ as variables, but then you show $A_i$. Using Manipulate[Subscript[l, 0], {Subscript[l, 0], 0, 1}] works as expected. $\endgroup$
    – Domen
    Jun 18 at 12:54
  • $\begingroup$ @larry The reason subscripted variables give trouble is that the head of a subscripted variable is not "Variable" but "Subscript". The are therefore no actual variables. $\endgroup$ Jun 18 at 13:40
  • $\begingroup$ @Domen The $A_i$ here is defined in advance as functions of $l_i$, which I didn't include here because they are quite complex. However, I realize that you are right in that the subscripted variable can work if the expression within Manipulate[] is a function directly as these variables. However, it won't work if the said expression is not an explicit expression of the subscripted control variable, like in my case. Is there any way to handle this? I mean the expression within Manipulate is defined outside Manipulate $\endgroup$
    – larry
    Jun 18 at 15:26


Your Answer

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