Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Suggestions for translating a Do[] loop ...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69793] Re: [mg69773] Suggestions for translating a Do[] loop ...
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Sat, 23 Sep 2006 04:44:45 -0400 (EDT)
  • References: <200609220505.BAA16564@smc.vnet.net>

On Sep 22, 2006, at 1:05 AM, David Annetts wrote:

> Hi,
>
> Given that a, b & r are lists of the same length, can anyone suggest a
> translation of the following Do[] loop to something functional?  It  
> looks
> like an ideal application for Fold, but for me, the loop going  
> backwards is
> really obscuring things.
>
> The loop is
>
> 	Do[
>     		r[[j]] = a[[j]] * (b[[j]] + r[[j + 1]]) / (1 + b[[j]] * r[[j
> + 1]]),
>     		{j, Length@a - 1, 1, -1}
>     		];
>
> with r[[Length@a]] = 0.

r=Reverse[FoldList[#2[[1]] (#2[[2]]+#1)/(1+#2[[2]] #1)&,0,Transpose 
[{Reverse[Most[a]],Reverse[Most[b]]}]]

Regards,

Ssezi


  • Prev by Date: Re: Extracting terms from an equation
  • Next by Date: Re: Suggestions for translating a Do[] loop ...
  • Previous by thread: Suggestions for translating a Do[] loop ...
  • Next by thread: Re: Suggestions for translating a Do[] loop ...