Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Can't use subscripted variables in function definition?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124065] Can't use subscripted variables in function definition?
  • From: Chris Young <cy56 at comcast.net>
  • Date: Sat, 7 Jan 2012 05:25:01 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

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




  • Prev by Date: Re: How to plot divergence of gradient as contour
  • Next by Date: Re: ParametricPlot3D vs Reduce
  • Previous by thread: Re: MatrixPower problem
  • Next by thread: Re: Can't use subscripted variables in function definition?