Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Assignment problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86259] Re: Assignment problem
  • From: "jwmerrill at gmail.com" <jwmerrill at gmail.com>
  • Date: Fri, 7 Mar 2008 02:26:59 -0500 (EST)
  • References: <fqo8o1$suo$1@smc.vnet.net>

On Mar 6, 3:07 am, Marco Gabiccini <m.gabicc... at ing.unipi.it> wrote:
> Hi all,
>
> I would like to do something like:
>
> For[ i=1, i<n, i++, ToExpression[ "q" <> ToString[i] ] = 0 ]
>
> that is assigning q1=0, q2=0, etc... but it does not work.

Just need to through in an Evaluate in the right place (this seems to
be the solution to a lot of problems in Mathematica).

For[i = 1, i < n, i++, Evaluate[ToExpression["q" <> ToString[i]]] = 0]

Do (or Table if you want to see what you've just assigned) would be a
little cleaner here.  Along with a couple other functions like Map and
Nest, these can almost always be used to rewrite a For expression more
cleanly.

Do[Evaluate[ToExpression["q" <> ToString[i]]] = 0, {i, n-1}]

Good Luck,

JM


  • Prev by Date: Re: Error in Interpolation of multi-d datas
  • Next by Date: Re: Assignment problem
  • Previous by thread: Re: Assignment problem
  • Next by thread: Re: Assignment problem