Message Boards Message Boards

5 Replies
2 Total Likes
View groups...
Share this post:

Assigning values to subscripted variables

Posted 10 years ago

Hi, I am trying to assign a value to a variable (g). This variable has a subscript composed of two more variables (j,k) separated by an invisible comma. J and k are used for indexing purposes. It seems that Mathematica can't assign a value (3 for example) to the indexed g. Or did I do something wrong?

 Subscript[g, j\[InvisibleComma]k] /. {j -> 2, k -> 2, 
  Subscript[g, 2\[InvisibleComma]2] -> 3}

Thanks in advance.

5 Replies
Posted 10 years ago

The only problem is that Subscript[] doesn't accept the invisible comma. (I'll leave that explanation for the experts). With a "visible" comma the code works as expected.

Subscript[g, j, k] /. {j -> 2, k -> 2, Subscript[g, 2, 2] -> 3}

with a value of 3 for the expression (but you didn't assign it to anything). Symbols formatted with visible or invisible commas in the subscript are the same symbol. Your other code should work.

NB: In the documentation section "tutorial/MakingDefinitionsForIndexedObjects" is the statement

You can think of the expression a[i] as being like an "indexed" or "subscripted" variable.

POSTED BY: Douglas Kubler
Posted 10 years ago

I used matrices instead of Subscript indexing. It worked as it should. Then I read your comment about the subject. And I tried the code with a visible comma as you suggested and it worked perfectly. My formulas should look now like the classical forms.

Thanks for your suggestions.


They are also problems converting them to strings, as the subscript is turned into a line feed.

POSTED BY: Frank Kampas
Posted 10 years ago

Subscripted variables are not "real" variables and users ask again and again why they aren't working the way the user expects.

Try carefully reading all the advice in SubscriptedVariables101.nb

POSTED BY: Bill Simpson
Posted 10 years ago

Thanks for the fast replies. I didn't find any hint to this in the Mathematica documentations about this issue. And of course, I didn't know either that I hit a "hot topic" by chance. Anyways, the thing is that I am trying to calculate Christoffel symbols for some coordination conversions. The subscripts and the superscripts are essential in the classical form of the equations and they keeps messing up my calculations. It seems that I have to find away around those trouble makers.

Thank you again

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract