Re: defining consecutive variables
- To: mathgroup at smc.vnet.net
- Subject: [mg99462] Re: [mg99392] defining consecutive variables
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Wed, 6 May 2009 05:24:07 -0400 (EDT)
- References: <200905050937.FAA20502@smc.vnet.net>
- Reply-to: drmajorbob at bigfoot.com
Why not call each matrix q[n], rather that qn? It's more flexible
programmatically, and what's the downside?
Bobby
On Tue, 05 May 2009 04:37:58 -0500, Jason <jbiggs2 at uoregon.edu> 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
>
--
DrMajorBob at bigfoot.com
- References:
- defining consecutive variables
- From: Jason <jbiggs2@uoregon.edu>
- defining consecutive variables