Re: Clear subscripted variables
- To: mathgroup at smc.vnet.net
- Subject: [mg58290] Re: [mg58276] Clear subscripted variables
- From: Pratik Desai <pdesai1 at umbc.edu>
- Date: Sun, 26 Jun 2005 01:33:52 -0400 (EDT)
- References: <200506250556.BAA12738@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, Here is what I think the problem is Why is x equal to x\_i? Even if it is, how can mathematica know it I think what you can try is Table[Subscript[x, i] = 1, {i, 1, 2}] (*Table[Unset[Subscript[x, i]], {i, 1, 2}] Table[Subscript[x, i], {i, 1, 2}]*) You can uncomment the unset table to clear the variables, or better yet write a module to do it (i.e Unset the subscipted variables) Here is a rough version of the same unsetmod[x_, list_] := Module[{list1}, list1 = list; Table[Unset[Subscript[x, list1[[s]]]], {s, 1, Length[list]}]] Table[Subscript[x, i] = 1, {i, 1, 5}] (*unsetmod[x, Range[2]]*) Table[Subscript[x, i], {i, 1, 5}] Best regards Pratik -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134
- References:
- Clear subscripted variables
- From: "Mukhtar Bekkali" <mbekkali@gmail.com>
- Clear subscripted variables