Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Using a loop to fill an array' topicStudent Support Forum > General > "Using a loop to fill an array"

Next Comment >Help | Reply To Topic
Author Comment/Response
Miguel
10/26/12 6:49pm

Hi

I would like to use a Do loop to fill an array. Something like:

Do[ abc[[i]] = i^2, {i, 1, 5} ]

Hoping that the result is:

abc = {1, 4, 9, 16, 25}

But I get an error instead:
"Set::noval: Symbol abc in part assignment does not have an immediate value"

Now, I know that:

abc = Table [i^2, {i, 1, 5}]

Will do the job, but I would like eventually to fill two or more arrays in a single loop. Is there a way to do this?





URL: ,

Subject (listing for 'Using a loop to fill an array')
Author Date Posted
Using a loop to fill an array Miguel 10/26/12 6:49pm
Re: Using a loop to fill an array jf 10/27/12 1:02pm
Re: Re: Using a loop to fill an array Miguel 10/28/12 11:08pm
Next Comment >Help | Reply To Topic