MathGroup Archive 2010

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

Search the Archive

Re: Assign value to variable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111255] Re: Assign value to variable
  • From: James Stein <mathgroup at stein.org>
  • Date: Sun, 25 Jul 2010 01:59:17 -0400 (EDT)

Big Correction to my preceding post!
Tricked by my own cockpit error.
Apologies to all. Try this instead:

n = 4;(*# of desired variables*)
Quiet [ Remove["co*"], Remove::"rmnsm"];
set = Function[#1 = #2];
Table[Symbol["co" <> ToString[ i ] ], {i, 1, n}]
For[i = 1, i <= n, i++, set[%[ [ i ] ], i^3] ]
{co1, co2, co3}

On Sat, Jul 24, 2010 at 4:39 PM, James Stein <mathgroup at stein.org> wrote:

> Perhaps something like this?
>
> n = 4; (* # of desired variables *)
> co = Table["co" <> ToString[i], {i, 1, n}];
> For[ i = 1, i <= n, i++, co [ [ i ] ] = i ^ 2 ] ;
>
>
>
>
> On Sat, Jul 24, 2010 at 2:07 AM, miguelwon <miguelwon at gmail.com> wrote:
>
>> Hello.
>>
>> I'm working with some expressions that are dependent of several
>> variables co1, co2, ... , con. I would like to know how can I assign
>> values iteratively to some of these variables. I tried:
>>
>> For[i=1,i<=100,i++,
>> Symbol["co"<>ToString[i]]=0;
>> ];
>>
>> but it doesn't work. For each iteration it says coi is Protected.
>> Can someone help me?
>>
>> Thanks
>>
>>
>



  • Prev by Date: Re: Assign value to variable
  • Next by Date: Re: Assign value to variable
  • Previous by thread: Re: Assign value to variable
  • Next by thread: Re: Assign value to variable