MathGroup Archive 2005

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

Search the Archive

Re: filling in an array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55362] Re: filling in an array
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sun, 20 Mar 2005 04:11:54 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 3/19/05 at 4:47 AM, andreajagger_8 at hotmail.com (dumb_founded)
wrote:

>How can I input values into an array most efficiently?  I tried the
>code below, but it doesn't work.  The kernel starts working through
>the loop and never gets out.

>Array[b, 10];
>For[i = 1, i = 10, b[i] = i/10]

This code suggests you think Array[b,10] creates an array named b with 10 elements. It doesn't.

As can be seen by

Array[b, 10]
{b[1], b[2], b[3], b[4], b[5], 
 b[6], b[7], b[8], b[9], b[10]}

Array creates a list 10 elements where the integers are supplied to b as arguements. So,

Array[1/#&,10]

will create the array you want. Alternatively,

Table[1/n,{n,10}]

will do what you want.

Also even if Array did work as you seem to expect, your For loop would not work. To set an indvidual element to a specific value the syntax is either

Part[b,2] = 2 or

b[[2]] = 2

--
To reply via email subtract one hundred and four


  • Prev by Date: Re: a simplification problem
  • Next by Date: Re: filling in an array
  • Previous by thread: Re: filling in an array
  • Next by thread: Re: filling in an array