Re: Initializing subscripted variables
- To: mathgroup at smc.vnet.net
- Subject: [mg24910] Re: [mg24879] Initializing subscripted variables
- From: BobHanlon at aol.com
- Date: Sun, 20 Aug 2000 01:34:58 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 8/19/2000 5:06:23 AM, hpd1 at is2.nyu.edu writes: > I want to define a function recursively, and must initialize the >value of the first few instances. For example: > f[1]=f[2]=f[3]=f[4]=1; f[n_]:=f[n-1]+f[n-2]+f[n-3]-f[n-4] >Here's the question: is there a way to write a function, e.g., a Table, >that >will generate the code preceding the semicolon above? > It is easy to generate a list of f[1], f[2], . . ., f[n], by >Threading f across the Range of desired initial subscripted variables. > My >problem is how to join the listed initial subscripted variables with a >single equals sign. (It is fairly easy to get the Boolean double-equals >sign between them, but I've discovered no way to get the single equals >sign.) > Pick one (f[#] = 1) & /@ Range[4]; Table[f[n] = 1, {n, 4}]; (# = 1) & /@ Table[f[n], {n, 4}]; Evaluate[Table[f[n], {n, 4}]] = Table[1, {4}]; Bob Hanlon