MathGroup Archive 2005

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

Search the Archive

Re: help working with functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60000] Re: [mg59987] help working with functions
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 28 Aug 2005 03:07:36 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

f[i_,j_,n_]:= Module[{k=0},
      Nest[
        Append[#,#[[-2]]+#[[-1]]+i*j^(k++)]&, 
        {0,1}, n-2]];

f[0,4,10]

{0,1,1,2,3,5,8,13,21,34}


Bob Hanlon

> 
> From: "hawkmoon269" <rson at new.rr.com>
To: mathgroup at smc.vnet.net
> Date: 2005/08/27 Sat AM 04:11:20 EDT
> Subject: [mg60000] [mg59987] help working with functions
> 
> I have the following program written:
> 
> Clear[a]; Clear[seq];
> seq = Array[a,10,0]; a[0]=0; a[1]=1;
> Do[a[k] = a[k-1] + a[k-2] + 0 4^(k-2), {k,2,10}];
> seq
> 
> It works fine and correctly outputs
> 
> {0, 1, 1, 2, 3, 5, 8, 13, 21, 34}
> 
> My sense,though, is that this is inelegant newbie code and am
> interested in hearing alternative ways to program with the same output.
>  Also, I would like to generalize this as a callable function with
> arguments i,j,n...something like:
> 
> f[i_,j_,n_]:=
> Clear[a]; Clear[seq];
> seq = Array[a,n,0]; a[0]=0; a[1]=1
> Do[a[k] = a[k-1] + a[k-2] + i j^(k-2), {k,2,n}]
> seq
> 
> So that
> 
> f[0,4,10]
> 
> would output
> 
> {0, 1, 1, 2, 3, 5, 8, 13, 21, 34}
> 
> I've tried variants of the foregoing, but can't get it to work
> correctly...
> 
> Many thanks in advance for ideas and assistance etc.
> 
> h
> 
> 


  • Prev by Date: Solution from Reduce as boundaries for Distribution
  • Next by Date: RasterGraphics[]
  • Previous by thread: Re: help working with functions
  • Next by thread: Re: help working with functions