Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7638
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Can't use subscripted variables in function definition? |
| Date | 2012-01-07 10:29 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <je96qv$j85$1@smc.vnet.net> (permalink) |
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 — Next in thread | Find similar | Unroll 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