Can we use letter with a subscript as a variable in Mathematica?
Yes you can, with limitations.
You have at least three different ways to make an assignment to a subscripted symbol a0 :
make a rule for
Subscript
make a rule for
a
"symbolize" a0 using the Notation package/palette
In each case below, when I write e.g. Subscript[a, 1]
this can also be entered as a1 by typing a then Ctrl+_ then 1.
When you write:
Subscript[a, 1] = "dog";
You make an assignment to Subscript
:
DownValues[Subscript]
{HoldPattern[a1] :> "dog"}
You make a rule for a
by using TagSet
:
a /: Subscript[a, 2] = "cat";
UpValues[a]
{HoldPattern[a2] :> "cat"}
If you use the Notation palette you mess with underlying Box forms behind the scenes, allowing for assignment to OwnValues
:
Each of these can be cleared with either Unset
or TagUnset
:
Subscript[a, 1] =.
a /: Subscript[a, 2] =.
You can also do this:
<< Notation`
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]
If you want to, you can import the Notation package first, then use the Symbolize function, so you don't have to use the ParsedBoxWrapper function, and just enter _,(ctrl+_),_
. What this does, is set a pattern matching a subscripted character as a symbol. Mathematica will then treat expressions matching this form as a single variable.
This doesn't seem to affect functions that use subscripts in their definition such as the partial differential function.