Re: How to define a list of functions/variables

• To: mathgroup at smc.vnet.net
• Subject: [mg102227] Re: How to define a list of functions/variables
• From: Peter Breitfeld <phbrf at t-online.de>
• Date: Sat, 1 Aug 2009 04:05:02 -0400 (EDT)
• References: <h4uf5o\$j1r\$1@smc.vnet.net>

```Haibo Min wrote:

> Hello, everyone.
>
> I want to define a list of variables "qi" and "Omegai", where q and
> Omega are both vectors and "i" denotes the ith vector, i.e.,
> qi[t]={qi1[t],qi2[t],qi3[t]}, Omegai[t]={Omegai1[t],Omega2[t],Omegai3[t]}.
>
> then I use the following code.
>
> eqns[n_Integer] /; Positive[n] :=
>  Table[{Subscript[q, i][t_] := {Subscript[q, i1][t],
>      Subscript[q, i2][t], Subscript[q, i3][t]},
>    Subscript[\[Omega], i][t_] := {Subscript[\[Omega], i1][t],
>      Subscript[\[Omega], i2][t], Subscript[\[Omega], i3][t]}}, {i, n}]
>
> but it shows that: eqns[2]={{Null, Null}, {Null, Null}}
> why?
>
> Thanks!
>
> Regards,
> Haibo
>

First you can't use i1,i2,i3 hoping they get evaluated to 11,12,12,...
because they are variables "of their own right", so were not affected
by the Table iterator {i,n}.

Second, in this case I would use Set (=) instead of SetDelayed (:=) for
the assignments of the vectors.

ClearAll[Subscript];
eqns[n_Integer] /; Positive[n] :=
Table[{Subscript[q, i][t_] = {Subscript[q, i, 1][t],
Subscript[q, i, 2][t], Subscript[q, i, 3][t]},
Subscript[\[Omega], i][t_] = {Subscript[\[Omega], i, 1][t],
Subscript[\[Omega], i, 2][t], Subscript[\[Omega], i, 3][t]}},
{i, n}]

Then:

eqns[2]

gives

{{{Subscript[q, 1, 1][t], Subscript[q, 1, 2][t],
Subscript[q, 1, 3][t]}, {Subscript[\[Omega], 1, 1][t],
Subscript[\[Omega], 1, 2][t],
Subscript[\[Omega], 1, 3][t]}}, {{Subscript[q, 2, 1][t],
Subscript[q, 2, 2][t],
Subscript[q, 2, 3][t]}, {Subscript[\[Omega], 2, 1][t],
Subscript[\[Omega], 2, 2][t], Subscript[\[Omega], 2, 3][t]}}}

and e.g.

Subscript[q, 2][t]

gives

{Subscript[q, 2, 1][t], Subscript[q, 2, 2][t], Subscript[q, 2, 3][t]}

If you change the assignments of the vectors to SetDelayed, this will
give no output, so you get "Null", but your vectors *are* defined,
and the input

Subscript[q,2][t]

will give the same as above.

--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

```

• Prev by Date: Re: Mapping GPS data
• Next by Date: Re: Finding the Position of Elements in a List that
• Previous by thread: Re: How to define a list of functions/variables
• Next by thread: Re: DOCS: debugger + theorem prover