help working with functions
- To: mathgroup at smc.vnet.net
- Subject: [mg59987] help working with functions
- From: "hawkmoon269" <rson at new.rr.com>
- Date: Sat, 27 Aug 2005 04:11:20 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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
- Follow-Ups:
- Re: help working with functions
- From: stephen layland <layland@wolfram.com>
- Re: help working with functions
- From: ggroup@sarj.ca
- Re: help working with functions