Re: Can't use subscripted variables in function definition?

• To: mathgroup at smc.vnet.net
• Subject: [mg124234] Re: Can't use subscripted variables in function definition?
• From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
• Date: Sat, 14 Jan 2012 02:59:21 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <je96qv\$j85\$1@smc.vnet.net>

```Subscripted variables are still a bit tricky as they have been from the
beginning, i.e. Mathematica 8 has not improved upon this.

To use a subscripted variable in a function definition, you need a colon
after the symbol, e.g.

f[xsub1:_]=...

However, you need to use the Notation package and Symbolize all your
subscripted variables. BTW, you have to use the Symbolize button on the
popup palette, not just type Symbolize (I don't know why).

If you like, I could send you a short nb with an example.

In spite of the overhead of using "nice" notation, I find that the
readability, especially after some time has gone by, to be more than
worth it.

Kevin

On 1/7/2012 5:29 AM, Chris Young wrote:
> What is the status of subscripted variables in Mathematica now? Can't
> they finally be used as regular variables? Or is there some workaround
> so that they can be? This is time-honored, very intuitive mathematical
> notation that should be available, IMO.
>
> Chris Young
> cy56 at comcast.net
>
>
> In[1449]:= a = 1; b = 1; c = Sqrt[2];
> {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]} = {0, 1, 0};
> {Subscript[y, 1], Subscript[y, 2], Subscript[y, 3]} = {0, 0, 1};
>
> In[1455]:=
> P = {{Subscript[x, 1], Subscript[y, 1]}, {Subscript[x, 2], Subscript[
>      y, 2]}, {Subscript[x, 3], Subscript[y, 3]}};
>
> In[1452]:=
> inCtr = {{a, b, c}.{Subscript[x, 1], Subscript[x, 2], Subscript[x,
>       3]}/(a + b +
>      c), {a, b, c}.{Subscript[y, 1], Subscript[y, 2], Subscript[y,
>       3]}/(a + b + c)};
>
> shrinkToInCtr[s_, Polygon[P_List, opts___]] :=
>   Module[
>    {
>     a, b, c,
>     Subscript[x, 1], Subscript[x, 2], Subscript[x, 3],
>     Subscript[y, 1], Subscript[y, 2], Subscript[y, 3],
>     inCtr
>     },
>
>    a = Norm[P[[3]] - P[[2]]];
>    b = Norm[P[[1]] - P[[3]]];
>    c = Norm[P[[2]] - P[[1]]];
>
>    {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]} = {P[[1, 1]],
>      P[[2, 1]], P[[3, 1]]};
>    {Subscript[y, 1], Subscript[y, 2], Subscript[y, 3]} = {P[[1, 2]],
>      P[[2, 2]], P[[3, 2]]};
>
>    inCtr = {{a, b, c}.{Subscript[x, 1], Subscript[x, 2], Subscript[x,
>        3]}/(a + b +
>       c), {a, b, c}.{Subscript[y, 1], Subscript[y, 2], Subscript[y,
>        3]}/(a + b + c)};
>
>    Polygon[(1 - s) (# - inCtr) + inCtr&  /@ P, opts]
>    ]
>
> In[1456]:= shrinkToInCtr[s_, Polygon[P_List, opts___]]
>
> In[1457]:= shrinkToInCtr[0.1, Polygon[P]]
>
> During evaluation of In[1457]:=
> Module::lvsym :  "Local variable specification \[NoBreak]{a\$, b\$, c\$, \
> \!\(\*SubscriptBox[\(x\), \(1\)]\), \!\(\*SubscriptBox[\(x\), \
> \(2\)]\), \!\(\*SubscriptBox[\(x\), \(3\)]\), \
> \!\(\*SubscriptBox[\(y\), \(1\)]\), \!\(\*SubscriptBox[\(y\), \
> \(2\)]\), \!\(\*SubscriptBox[\(y\), \(3\)]\), inCtr\$}\[NoBreak] \
> contains \[NoBreak]\!\(\*SubscriptBox[\(x\), \(1\)]\)\[NoBreak], \
> which is not a symbol or an assignment to a symbol. \!\(\*ButtonBox["\
> \[RightSkeleton]",
> Appearance->{Automatic, None},
> ButtonData:>"paclet:ref/message/Module/lvsym",
> ButtonNote->"Module::lvsym"]\)"
>
> Out[1457]= Module[{a\$, b\$, c\$, Subscript[x, 1], Subscript[x, 2],
>    Subscript[x, 3], Subscript[y, 1], Subscript[y, 2], Subscript[y, 3],
>    inCtr\$}, a\$ =
>    Norm[{{0, 0}, {1, 0}, {0, 1}}[[3]] - {{0, 0}, {1, 0}, {0, 1}}[[2]]];
>    b\$ = Norm[{{0, 0}, {1, 0}, {0, 1}}[[1]] - {{0, 0}, {1, 0}, {0, 1}}[[
>       3]]]; c\$ =
>    Norm[{{0, 0}, {1, 0}, {0, 1}}[[2]] - {{0, 0}, {1, 0}, {0, 1}}[[
>       1]]]; {Subscript[x, 1], Subscript[x, 2], Subscript[x,
>     3]} = {{{0, 0}, {1, 0}, {0, 1}}[[1, 1]], {{0, 0}, {1, 0}, {0, 1}}[[
>      2, 1]], {{0, 0}, {1, 0}, {0, 1}}[[3, 1]]}; {Subscript[y, 1],
>     Subscript[y, 2], Subscript[y,
>     3]} = {{{0, 0}, {1, 0}, {0, 1}}[[1, 2]], {{0, 0}, {1, 0}, {0, 1}}[[
>      2, 2]], {{0, 0}, {1, 0}, {0, 1}}[[3, 2]]};
>   inCtr\$ = {{a\$, b\$, c\$}.{Subscript[x, 1], Subscript[x, 2], Subscript[
>       x, 3]}/(a\$ + b\$ +
>      c\$), {a\$, b\$, c\$}.{Subscript[y, 1], Subscript[y, 2], Subscript[y,
>       3]}/(a\$ + b\$ + c\$)};
>   Polygon[((1 - 0.1) (#1 - inCtr\$) + inCtr\$&) /@ {{0, 0}, {1, 0}, {0,
>       1}}]]
>
>

```

• Prev by Date: Re: Solve stuck at 243
• Next by Date: Re: how can one use mathematica get the approximate derivative of {x,y} data points?
• Previous by thread: Re: Can't use subscripted variables in function definition?
• Next by thread: Re: Can't use subscripted variables in function definition?