# Create variables with subscripts automatically?

**URL:** <https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533>\
**Category:** Questions\
**Created:** [May 11, 2016, 4:17am UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533 "2016-05-11T04:17:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernagoga](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bernagoga/32/34147_2.png) [@bernagoga](https://community.wolfram.com/u/bernagoga)\
**Post date:** [May 11, 2016, 4:17am UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/1 "2016-05-11T04:17:51Z")

</div>

I’m currently working on a project and I have created by hand 20 variables with the form X [subscript i] [subscript j], and it is very tedious. I don’t want to do this 80 or 100 times by hand. Is there any way easier than this? Thanks in advance and sorry for the bad English.

---

<div class="post-metadata">

**Author:** ![bsimpson141421356](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bsimpson141421356](https://community.wolfram.com/u/bsimpson141421356)\
**Post date:** [May 11, 2016, 4:51am UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/2 "2016-05-11T04:51:45Z")

</div>

Perhaps

```
Table[Subscript[X, i, j], {i, 1, 10}, {j, 1, 10}]

```

and then scrape-n-paste as needed?

Be careful with subscripted variables because they are different from “ordinary” variables in some situations.

---

<div class="post-metadata">

**Author:** ![Vitaliyk](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vitaliyk/32/45591_2.png) [@Vitaliyk](https://community.wolfram.com/u/Vitaliyk)\
**Post date:** [May 11, 2016, 8:37am UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/3 "2016-05-11T08:37:11Z")

</div>

If you use your variables for real computations (as opposed to math typesetting) the I would consider labeling variables differently, as [@Bill Simpson](http://community.wolfram.com/web/bsimpson141421356) recommended too. The easiest:

```
Array[a, {3, 3}]

```

> {{a[1, 1], a[1, 2], a[1, 3]}, {a[2, 1], a[2, 2], a[2, 3]}, {a[3, 1], a[3, 2], a[3, 3]}}

then an example of computation is:

```
Solve[a[1, 2]^3 - a[1, 2] + 1 == 0, a[1, 2]];
TraditionalForm[Column[%]]

```

 ![2016-05-11_03-40-05.png](https://global.discourse-cdn.com/wolfram/original/3X/3/8/386e154e089009c7fd1ebf21f34f9c74847a41db.png)

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [May 11, 2016, 9:58am UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/4 "2016-05-11T09:58:44Z")

</div>

If you want to do anything with the variables, indeed do not use Subscript, it will generally be very confusing and frustrating…

The new function

```
Indexed

```

might be useful as well…

---

<div class="post-metadata">

**Author:** ![bernagoga](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bernagoga/32/34147_2.png) [@bernagoga](https://community.wolfram.com/u/bernagoga)\
**Post date:** [May 11, 2016, 6:19pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/5 "2016-05-11T18:19:12Z")

</div>

Thank you so much for answering so quickly. Your answer was the one I needed!

---

<div class="post-metadata">

**Author:** ![bernagoga](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bernagoga/32/34147_2.png) [@bernagoga](https://community.wolfram.com/u/bernagoga)\
**Post date:** [May 11, 2016, 6:20pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/6 "2016-05-11T18:20:21Z")

</div>

Thanks for the answer. Didnt know there would be such problems as I am merely starting

---

<div class="post-metadata">

**Author:** ![bernagoga](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bernagoga/32/34147_2.png) [@bernagoga](https://community.wolfram.com/u/bernagoga)\
**Post date:** [May 11, 2016, 6:21pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/7 "2016-05-11T18:21:26Z")

</div>

Thanks, will look into it. Didnt know there would be such problems with subscripts.

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [May 11, 2016, 6:23pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/8 "2016-05-11T18:23:25Z")

</div>

Not really a problem, more of a misconception. One should see Subscript merely as a typographical construct, nothing else. If one adheres to those confines generally there is no `problem’…

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [May 11, 2016, 8:15pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/9 "2016-05-11T20:15:24Z")

</div>

It is meanwhile routine on this platform that questions come up on the use of, or problems (i.e. “unexpected behavior”) with, `Subscript`. Sanders description of those as a “typographical construct” is just perfect!

Because in the beginning I had problems myself in proper understanding, I would like to give a little explanation:

If you have a variable (say `a`) and you make an assignment, that means that the variable gets an “ownvalue”:

```
a = 3;
OwnValues[a]
(* Out: {HoldPattern[a]\[RuleDelayed]3} *)

```

Whereas when you make the assignments:

![s1.png](https://global.discourse-cdn.com/wolfram/original/2X/a/a8e51740951578a84039e89e2de760954d89afd4.png)

there are no `OwnValues` at all! The point rather is that in a way you changed the properties of `Subscript`:

![s2.png](https://global.discourse-cdn.com/wolfram/original/3X/7/c/7c6af16e5e952fdeca27d2938f184bc16a727fbd.png)

This is pretty much the same as if you write:

```
f[1] = 3;

```

There is no problem in doing this, but one would not want to call `f[1]` a “variable”.

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [May 11, 2016, 8:34pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/10 "2016-05-11T20:34:18Z")

</div>

“Typographical construct” might indeed be a good addition to the documentation…

---

<div class="post-metadata">

**Author:** ![bsimpson141421356](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bsimpson141421356](https://community.wolfram.com/u/bsimpson141421356)\
**Post date:** [May 12, 2016, 4:21pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/11 "2016-05-12T16:21:50Z")

</div>

I am curious.

Is the seemingly often reported troublesome behavior of subscripted variables perhaps only an unexpected consequence of a design decision of convenience?

Or are there deep fundamental theoretical reasons that might be explained why it is just not possible for subscribed variables to behave like “ordinary” variables?

If it was just a decision of convenience, since giving people subscripts seems to compel them to use them and this behavior has for years caused confusion and unexpected problems, would there be any chance this design decision might be reconsidered and perhaps this problem could just go away? Would it break anything not relatively easily repaired if this were changed?

This is perhaps similar to the various "Form"s, which people seem compelled to use and are then confused when functions and operators do not then operate on the contained data exactly as if the Form were not present.

I vaguely remember something about a “principle of least surprise” from long long ago.

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [May 13, 2016, 12:52pm UTC](https://community.wolfram.com/t/create-variables-with-subscripts-automatically/8533/12 "2016-05-13T12:52:19Z")

</div>

I think the main problem is that Subscript[x,1] or so does not have Symbol as a Head, while a normal variable has, so it is not recognised and breaks everything… I think changing it will be (very) bad idea, as it will break everything. But introducing a new function IndexedVariable or so could work…
