Message Boards Message Boards

1
|
26432 Views
|
6 Replies
|
10 Total Likes
View groups...
Share
Share this post:

About Subscript and subscripted variables

Posted 11 years ago
I have problem with instantializing a variable with subscript.
Subscript[a, i, j] = \!\(

\*UnderoverscriptBox[\(\[Product]\), \(k = i\), \(j\)]
\*SubscriptBox[\(a\), \(k\)]\);
Subscript[a, i, j] /. {i -> 1, j -> 2}
Subscript[a, 1, 2]

Why can't I instantialize ai,j by directly assigning the subscripts with 1 and 2? 
POSTED BY: Moon Liu
6 Replies

A beginner's guide to subscripted variables is attached.

The question of commas in subscripts was treated last year in http://community.wolfram.com/groups/-/m/t/306808 .

Attachments:
POSTED BY: Bruce Miller

It's best to avoid trouble by not identifying subscripts in definitions. For example, if you are dealing with a_{i,j}, just define

a[i_, j_] := . . .

with subscripts serving as variables.

POSTED BY: S M Blinder
Posted 10 years ago

Does that mean that in a large model with many variables with subscripts we will have to define all the subscripted variables as functions like

a b[i,j]:=... and so on

I have been having terrible times with subscripts when I use "hidden comma" subscripted variables. Errors occur and Mathematica does not tell why erros occur. Sometimes I loose days to pinpoint the subscript problems. I belive that Mathematica has to find a better way to deal with subscripted variables....It is a nightmare if problems occur due to the subscript problems.

POSTED BY: Tugrul Temel
Posted 9 years ago

Thank you for your answer! What I try to do is to use European mechanical standards' constants and variable names as local variables inside Modules. Those names include several subscripts, and some of them include 1-3 commas in the subscript part.

I removed my example variable name from definition to expr part of the Module. The color changed from green to blue, and now it seems to be a global variable, because a value is returned when testing the variable outside the Module. The calculation inside the Module started to work, but I need to use local variables to avoid confusions.

Is it possible to use subscripts in local variable names?

Are the commas allowed in subscripts, when variables are used in Conditionals (If, Which...)?

POSTED BY: Kari K
Posted 10 years ago

I have also problems with subscripts. Are there any limitations in using subscripts in variable names?

"Local variable specification {contains Subscript[k, [Sigma]]=koosigma, \ which is an assignment to Subscript[k, [Sigma]]; only assignments to \ symbols are allowed"

POSTED BY: Kari K
Because there is a definition for Subscript[a, i, j] which matches only the specific symbols i and j, not the numbers 1 and 2. To have it work for any i and j, we could use Subscript[a, i_, j_]. See also this tutorial in the documentation.
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract