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


Groups > comp.soft-sys.math.mathematica > #7808

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From "Kevin J. McCann" <Kevin.McCann@umbc.edu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Can't use subscripted variables in function definition?
Date Sat, 14 Jan 2012 08:04:04 +0000 (UTC)
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <jerctk$1fu$1@smc.vnet.net> (permalink)
References <je96qv$j85$1@smc.vnet.net>
Lines 112
NNTP-Posting-Date 14 Jan 2012 08:04:23 GMT
NNTP-Posting-Host 00ff036f.news.twtelecom.net
X-Trace DXC=TIK`YamKk<k<hTOhR17AClC_A=>8kQj6mhHXa^^g6TZd7VQd:<OnFkaEFiONJ7[GofIN3eMWo:TLl
X-Complaints-To abuse@twtelecom.net
Xref x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:7808

Show key headers only | View raw


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}}]]
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web