Re: Converting list of subscripted variables into an array
- To: mathgroup at smc.vnet.net
- Subject: [mg118308] Re: Converting list of subscripted variables into an array
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Thu, 21 Apr 2011 03:10:51 -0400 (EDT)
This might get you started: Clear[subFunction] 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[c] Array[c[#1][#2] &, {9, 2}] {{Subscript[c, 1][1], Subscript[c, 1][2]}, {Subscript[c, 2][1], Subscript[c, 2][2]}, {Subscript[c, 3][1], Subscript[c, 3][2]}, {Subscript[c, 4][1], Subscript[c, 4][2]}, {Subscript[c, 5][1], Subscript[c, 5][2]}, {Subscript[c, 6][1], Subscript[c, 6][2]}, {Subscript[c, 7][1], Subscript[c, 7][2]}, {Subscript[c, 8][1], Subscript[c, 8][2]}, {Subscript[c, 9][1], Subscript[c, 9][2]}} Bobby On Wed, 20 Apr 2011 03:27:29 -0500, Christopher O. Young <cy56 at comcast.net> wrote: > > I have a long list that's supposed to represent points on 9 different > curves. I'd like to put them into an array C[j,k] where j is the index > for > the curves and k is the index for the points. > > Subscript[c1, 1] = {1.796875, 1.34375} > > Subscript[c1, 2] = {2.15625, 1.34375} > > Subscript[c1, 3] = {2.296875, 1.359375} > > Subscript[c1, 4] = {2.375, 1.46875} > > Subscript[c1, 5] = {2.46875, 1.671875} > ...... > > I'm new at pattern matching, and I'm having a hard time getting started > here. Can anyone steer me in the right direction? > > Chris Young > cy56 at comcast.net > IntuMath.org > > In[180]:= "c" <> IntegerString[1] > > > Out[180]= "c1" > > > > > In[181]:= Subscript["c" <> IntegerString[1], 2] > > > Out[181]= Subscript["c1", 2] > > > > > In[182]:= Evaluate[%] > > In[183]:= Subscript["c1", 2] > > > Out[183]= Subscript["c1", 2] > > > > > ToExpression[Subscript["c1", 2]] > > > > During evaluation of In[187]:= ToExpression::notstrbox: Subscript[c1, 2] > is > not a string or a box. ToExpression can only interpret strings or boxes > as > Mathematica input. >> > > > > Out[187]= $Failed > > > > > In[188]:= ToExpression[RowBox[{Subscript["c1", 2]}]] > > > > During evaluation of In[188]:= ToExpression::esntx: Could not parse > RowBox[{Subscript[c1, 2]}] as Mathematica input. >> > > > > Out[188]= $Failed > > > > > -- DrMajorBob at yahoo.com