Re: Assignment problem

• To: mathgroup at smc.vnet.net
• Subject: [mg86279] Re: Assignment problem
• From: "Michael Weyrauch" <michael.weyrauch at gmx.de>
• Date: Fri, 7 Mar 2008 02:30:42 -0500 (EST)
• References: <fqo8o1\$suo\$1@smc.vnet.net>

```Hello Marco,

this situation can be saved using Evaluate[].

Clear["q*"];

n = 5;

For[ i = 1, i < n, i++,

Evaluate[ToExpression[ "q" <> ToString[i]]] = 0]

Otherwise you would be assigning 0 to the symbol ToExpression, which is

of course not possible (and not sensible).

Michael

"Marco Gabiccini" <m.gabiccini at ing.unipi.it> schrieb im Newsbeitrag news:<fqo8o1\$suo\$1 at smc.vnet.net>...

> 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.

>

> I would not like to use the easy way out:

>

> For[ i=1, i<n, i++, q[i] = 0 ]

>

> of employing q[i] instead of qi.

>

> Can you help me please?

>

> Thanks,

>

> Marco

>

> Ing. Marco Gabiccini, PhD

> Assistant Professor of Applied Mechanics

> Dept. of Mechanical, Nuclear and Production Engineering

> University of Pisa

> Via Diotisalvi, 2, 56126 Pisa (PI) - Italy

> Phone: +39-050-836.676

> E-mail: m.gabiccini at ing.unipi.it

>

"Marco Gabiccini" <m.gabiccini at ing.unipi.it> schrieb im Newsbeitrag news:fqo8o1\$suo\$1 at smc.vnet.net...
> 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.
>
> I would not like to use the easy way out:
>
> For[ i=1, i<n, i++, q[i] = 0 ]
>
> of employing q[i] instead of qi.
>
> Can you help me please?
>
> Thanks,
>
> Marco
>
> Ing. Marco Gabiccini, PhD
> Assistant Professor of Applied Mechanics
> Dept. of Mechanical, Nuclear and Production Engineering
> University of Pisa
> Via Diotisalvi, 2, 56126 Pisa (PI) - Italy
> Phone: +39-050-836.676
> E-mail: m.gabiccini at ing.unipi.it
>
>

```

• Prev by Date: Re: Apply function to parts of a list
• Next by Date: Re: Apply function to parts of a list
• Previous by thread: Re: Assignment problem
• Next by thread: Re: Assignment problem