everyone! I hope to declare a variable with subscript as numbers, for example, $x_{10}$, $x_{11}$, $x_{01}$ as variables. Is it possible in mathematica? If so, how to implement it so that it treats $x_{10}$ as a variable? Thank you!
Asked
Active
Viewed 1,255 times
2 Answers
2
Format[x[i_, j_]] :=
Subscript[x, StringJoin[ToString /@ {i, j}]]
t = Total[{x[1, 0], x[1, 1], x[0, 1]}]

Solve[t == 1, x[0, 1]]

Bob Hanlon
- 157,611
- 7
- 77
- 198
2
Using the 'Notation' package, you can create real symbols from (not only!) subscripted variables:
Needs["Notation`"]
makesymbol[obj_]:=With[{},
If[NameQ@ToString@Unevaluated@obj,Remove@obj]; (* remove possibly existing symbol first *)
Symbolize@ParsedBoxWrapper@ToBoxes@obj;] (* then create the new symbol *)
With this function, you can create a symbol like so:
makesymbol[Subscript[x,"01"]]
Mathematica will now treat it the same as any other (simpler) symbol.
And the best part is:
- You have the same look&feel everywhere, both in your code and the generated output.
- It works for all kinds of notation, not only
Subscript
I hope this might be of some help to you.
Jinxed
- 3,753
- 10
- 24
Ctrl+_won't work? – DumpsterDoofus Feb 06 '15 at 01:23