MathGroup Archive 2005

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

Search the Archive

Re: filling in an array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55358] Re: [mg55347] filling in an array
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 20 Mar 2005 04:11:50 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

If you want b to be a discrete function defined for integer i, 1<=i<=10

Clear[b];
For[i=1,i<11,i++,b[i]=i/10]

{b[1],b[7],b[11]}

{1/10, 7/10, b[11]}

Clear[b]; 
Table[b[i]=i/10,{i,10}];

{b[1],b[7],b[11]}

{1/10, 7/10, b[11]}

Clear[b]; 
b[i_Integer?Positive/;i<11] := i/10;

{b[1],b[7],b[11]}

{1/10, 7/10, b[11]}

If you want b to be an array (vector)

Clear[b]; 
b=Table[i/10,{i,10}];

{b[[1]],b[[7]]}

{1/10, 7/10}

Clear[b]; 
b=Range[10]/10;

{b[[1]],b[[7]]}

{1/10, 7/10}


Bob Hanlon

> 
> From: "dumb_founded" <andreajagger_8 at hotmail.com>
To: mathgroup at smc.vnet.net
> Date: 2005/03/19 Sat AM 04:47:07 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg55358] [mg55347] filling in an array
> 
> 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]
> 
> 


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