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


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

Re: Can't use subscripted variables in function

From DrMajorBob <btreat1@austin.rr.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Can't use subscripted variables in function
Date 2012-01-14 07:55 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jerce9$19s$1@smc.vnet.net> (permalink)
References <je96qv$j85$1@smc.vnet.net> <jebngu$1bb$1@smc.vnet.net>

Show all headers | View raw


a[i] is less cluttered than Subscript[a,i], it works better as a variable,  
and it's easier to enter and access.

If you want a[i] to LOOK like Subscript[a,i] in displayed results, you can  
execute:

subFunction[
   a_Symbol] := (MakeExpression[SubscriptBox[ToString@a, i_], f_] :=
    MakeExpression[RowBox[{ToString@a, "[", i, "]"}]];
   MakeBoxes[a[i_], f_] :=
    SubscriptBox[MakeBoxes[a, f], MakeBoxes[i, f]])

subFunction[a]
Array[a, 10]

{Subscript[a, 1], Subscript[a, 2], Subscript[a, 3], Subscript[a, 4], \
Subscript[a, 5], Subscript[a, 6], Subscript[a, 7], Subscript[a, 8], \
Subscript[a, 9], Subscript[a, 10]}

You'll see subscripts only when a value is not defined, but that's true  
for subscripted variables, too. For instance:

a[2] = 3;
Subscript[a, 5] = 12;
Array[a, 10]

{Subscript[a, 1], 3, Subscript[a, 3], Subscript[a, 4], 12, \
Subscript[a, 6], Subscript[a, 7], Subscript[a, 8], Subscript[a, 9], \
Subscript[a, 10]}

and also

Table[Subscript[a, n], {n, 10}]

{Subscript[a, 1], 3, Subscript[a, 3], Subscript[a, 4], 12, \
Subscript[a, 6], Subscript[a, 7], Subscript[a, 8], Subscript[a, 9], \
Subscript[a, 10]}

Bobby

On Fri, 13 Jan 2012 03:52:54 -0600, Chris Young <cy56@comcast.net> wrote:

> On 2012-01-10 10:56:36 +0000, Ralph Dratman said:
>
>> Is this just a discussion about how things look on the screen -- or is
>> there some deeper difference between Mathematica's "array" indices and
>> properly-implemented subscripts?
>
> I was looking for subscripted variables to conveniently extend notation
> for things such as points determining a polynomial, and so on. Formulas
> to do this kind of thing appear in all the math refererences with
> subscripted variables, and I think it's the most natural notation.
> We're not really interested in an array of points, just the individual
> points, in this case. It's simply a more uncluttered notation.
>
> Chris
>
>


-- 
DrMajorBob@yahoo.com

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


Thread

Re: Can't use subscripted variables in function definition? Bill Rowe <readnews@sbcglobal.net> - 2012-01-08 09:26 +0000
  Re: Can't use subscripted variables in function definition? Armand Tamzarian <mike.honeychurch@gmail.com> - 2012-01-09 08:20 +0000
  Re: Can't use subscripted variables in function definition? Ralph Dratman <ralph.dratman@gmail.com> - 2012-01-10 10:56 +0000
    Re: Can't use subscripted variables in function definition? Chris Young <cy56@comcast.net> - 2012-01-13 09:54 +0000
    Re: Can't use subscripted variables in function definition? Armand Tamzarian <mike.honeychurch@gmail.com> - 2012-01-14 07:58 +0000
      Re: Can't use subscripted variables in function definition? Armand Tamzarian <mike.honeychurch@gmail.com> - 2012-01-15 09:50 +0000
  Re: Can't use subscripted variables in function DrMajorBob <btreat1@austin.rr.com> - 2012-01-14 07:55 +0000

csiph-web