MathGroup Archive 2009

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

Search the Archive

Re: defining consecutive variables

  • To: mathgroup at
  • Subject: [mg99456] Re: defining consecutive variables
  • From: Jens-Peer Kuska <kuska at>
  • Date: Wed, 6 May 2009 05:23:00 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <gtp199$joi$>
  • Reply-to: kuska at


what is wrong with q[0], q[1], ..
And with


(q[#]=f[#]) & /@  Range[0, 40]



Jason wrote:
> I have a code where I need to define a large number of variables as matrices, called q1,q2,q3......qn. I'd like to be able to define them all without writing out n assignment lines, so a Do loop seems appropriate to me but I don't know how to assign sequential variable names. This gets the job done but it is really ugly IMO
> f[x_] := Table[x RandomReal[], {n, 5}, {np, 5}](*for example*)
> Do[ToExpression["q" <> ToString[n] <> "=f[n]"], {n, 0, 40}]
> at the end of which I have 41 matrices which I can call as q0,q1, etc. Is this the best way to accomplish this task?
> Thanks

  • Prev by Date: Re: Some function like Positionbut uses criteria, not pattern?
  • Next by Date: Re: Reading csv with ;
  • Previous by thread: Re: defining consecutive variables
  • Next by thread: Re: defining consecutive variables