MathGroup Archive 2009

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

Search the Archive

Re: How to define a list of functions/variables

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.

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




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


{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


will give the same as above.

Peter Breitfeld, Bad Saulgau, Germany --

  • 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