Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7638 > unrolled thread

Can't use subscripted variables in function definition?

Started byChris Young <cy56@comcast.net>
First post2012-01-07 10:29 +0000
Last post2012-01-14 08:04 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Can't use subscripted variables in function definition? Chris Young <cy56@comcast.net> - 2012-01-07 10:29 +0000
    Re: Can't use subscripted variables in function definition? "Kevin J. McCann" <Kevin.McCann@umbc.edu> - 2012-01-14 08:04 +0000

#7638 — Can't use subscripted variables in function definition?

FromChris Young <cy56@comcast.net>
Date2012-01-07 10:29 +0000
SubjectCan't use subscripted variables in function definition?
Message-ID<je96qv$j85$1@smc.vnet.net>
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@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},
BaseStyle->"Link",
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}}]]

[toc] | [next] | [standalone]


#7808

From"Kevin J. McCann" <Kevin.McCann@umbc.edu>
Date2012-01-14 08:04 +0000
Message-ID<jerctk$1fu$1@smc.vnet.net>
In reply to#7638
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@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},
> BaseStyle->"Link",
> 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}}]]
>
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web