Re: help working with functions
- To: mathgroup at smc.vnet.net
- Subject: [mg60001] Re: [mg59987] help working with functions
- From: "David Park" <djmp at earthlink.net>
- Date: Sun, 28 Aug 2005 03:07:37 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Clear[a]; Clear[seq];
seq = Array[a, 10, 0];
a[0] = 0;
a[1] = 1;
a[k_] := a[k] = a[k - 1] + a[k - 2]
seq
{0, 1, 1, 2, 3, 5, 8, 13, 21, 34}
a[115]
483162952612010163284885
I don't see what the 0 4^(k - 2) term is contributing because it is always
zero - so I left it out. Perhaps you intended something else?
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: hawkmoon269 [mailto:rson at new.rr.com]
To: mathgroup at smc.vnet.net
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