Re: Can't use subscripted variables in function
- To: mathgroup at smc.vnet.net
- Subject: [mg124218] Re: Can't use subscripted variables in function
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sat, 14 Jan 2012 02:53:48 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <je96qv$j85$1@smc.vnet.net> <jebngu$1bb$1@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
a[i] is less cluttered than Subscript[a,i], it works better as a variable, and it's easier to enter and access. If you want a[i] to LOOK like Subscript[a,i] in displayed results, you can execute: subFunction[ a_Symbol] := (MakeExpression[SubscriptBox[ToString@a, i_], f_] := MakeExpression[RowBox[{ToString@a, "[", i, "]"}]]; MakeBoxes[a[i_], f_] := SubscriptBox[MakeBoxes[a, f], MakeBoxes[i, f]]) subFunction[a] Array[a, 10] {Subscript[a, 1], Subscript[a, 2], Subscript[a, 3], Subscript[a, 4], \ Subscript[a, 5], Subscript[a, 6], Subscript[a, 7], Subscript[a, 8], \ Subscript[a, 9], Subscript[a, 10]} You'll see subscripts only when a value is not defined, but that's true for subscripted variables, too. For instance: a[2] = 3; Subscript[a, 5] = 12; Array[a, 10] {Subscript[a, 1], 3, Subscript[a, 3], Subscript[a, 4], 12, \ Subscript[a, 6], Subscript[a, 7], Subscript[a, 8], Subscript[a, 9], \ Subscript[a, 10]} and also Table[Subscript[a, n], {n, 10}] {Subscript[a, 1], 3, Subscript[a, 3], Subscript[a, 4], 12, \ Subscript[a, 6], Subscript[a, 7], Subscript[a, 8], Subscript[a, 9], \ Subscript[a, 10]} Bobby On Fri, 13 Jan 2012 03:52:54 -0600, Chris Young <cy56 at comcast.net> wrote: > On 2012-01-10 10:56:36 +0000, Ralph Dratman said: > >> Is this just a discussion about how things look on the screen -- or is >> there some deeper difference between Mathematica's "array" indices and >> properly-implemented subscripts? > > I was looking for subscripted variables to conveniently extend notation > for things such as points determining a polynomial, and so on. Formulas > to do this kind of thing appear in all the math refererences with > subscripted variables, and I think it's the most natural notation. > We're not really interested in an array of points, just the individual > points, in this case. It's simply a more uncluttered notation. > > Chris > > -- DrMajorBob at yahoo.com