Re: Re: Recursion on a list
- To: mathgroup at smc.vnet.net
- Subject: [mg28940] Re: [mg28908] Re: Recursion on a list
- From: Richard Palmer <mapsinc at bellatlantic.net>
- Date: Sat, 19 May 2001 22:27:57 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I think a form like x = FoldList[Times,1,1+Rest[r]] would be still more efficient and get the job done. It avoids a lot of interpretive function evaluations. -- Richard Palmer 12 Garvey Road Framingham, MA 01701 508 877-3862 on 5/18/01 1:13 AM, Stephen P Luttrell at luttrell at signal.dra.hmg.gb wrote: > > "msc" <mscmsc at mediaone.net> wrote in message news:9e02kg$305 at smc.vnet.net... >> Greetings, >> >> I'm looking for an efficient method (i.e., with the use of an explicit > loop) >> for the following problem. I am working with large lists (several thousand >> elements) of data. Denote one such list r. I would like to define a new > list >> x such that: >> >> >> x[0] = 1.0 >> >> x[t] = x[t-1]*(1.0 + r[t]) >> >> Can anyone suggest an efficient way? > > This does what you want: > > FoldList[#1(1+#2)&,1,r] > > where r is the list of r-values, which would have been {r[1],r[2],r[3],..} > in your notation. > > -- > Stephen P Luttrell > DERA, Malvern, U.K. > luttrell at signal.dera.gov.uk > > >