Re: Clear subscripted variables

• To: mathgroup at smc.vnet.net
• Subject: [mg58294] Re: Clear subscripted variables
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sun, 26 Jun 2005 01:33:56 -0400 (EDT)
• Organization: The Open University, Milton Keynes, England
• References: <d9ispk\$cpd\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Mukhtar Bekkali wrote:
> Here is the code (x\_i stands for x subscript i):
>
> Table[{Print[x\_i = i]; Clear[x]; Remove[x]; Unset[x]; Print[x\_i]},
> {i, 1, 2}]
>
> I expected that x\_i is cleared at the end of the loop but it isn't
>
> If I insert Clear[Subscript] in the loop then it is cleared, but not
> desirable since it clears all variables with subscripts.
>
> What command shall I use to clear specific subscripted variables?
>
> Mukhtar Bekkali
>
Hi Mukhtar,

Subscripted variables are not symbols in Mathematica: *Clear* and
*Remove* complain about that whereas *Unset* works.

You can use the package *Symbolize* to more or less transform
subscripted variables into symbols. For example,

In[1]:=
\!\(x\_1 = 1\)
Out[1]=
1
In[2]:=
\!\(x\_1\)
Out[2]=
1
In[3]:=
\!\(Clear[x\_1]\)
From In[3]:=
\!\(\*
RowBox[{\(Clear::"ssym"\), \(\(:\)\(\ \)\), "\<\"\\!\\(x\\_1\\) is
not a \
symbol or a string. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\",
ButtonStyle->\
ButtonData:>\\\"Clear::ssym\\\"]\
\\)\"\>"}]\)
In[4]:=
\!\(Remove[x\_1]\)
From In[4]:=
\!\(\*
RowBox[{\(Remove::"ssym"\), \(\(:\)\(\ \)\), "\<\"\\!\\(x\\_1\\) is
not a \
symbol. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", \
ButtonData:>\\\"Remove::ssym\\\"]\\)\"\>"}]\)
In[5]:=
\!\(FullForm[HoldForm[x\_1]]\)
Out[5]//FullForm=
HoldForm[Subscript[x,1]]
In[6]:=
\!\(Unset[x\_1]\)
In[7]:=
\!\(x\_1\)
Out[7]=
\!\(x\_1\)
In[8]:=
Needs["Utilities`Notation`"]
In[9]:=
\!\(\*
RowBox[{"Symbolize", "[",
TagBox[\(x\_1\),
NotationBoxTag,
TagStyle->"NotationTemplateStyle"], "]"}]\)
In[10]:=
\!\(x\_1 = 2\)
Out[10]=
2
In[11]:=
\!\(Clear[x\_1]\)
In[12]:=
\!\(x\_1\)
Out[12]=
\!\(x\_1\)

Hope this helps,
/J.M.

```

• Prev by Date: Re: Spline
• Next by Date: Mathematica Visualization site - update
• Previous by thread: Re: Clear subscripted variables
• Next by thread: Re: Clear subscripted variables