 Calculating the sum of an expression without loops

So I want to find the sum of this expression:
1 +(2 /3)+(2/3)(4/5)+(2/3)(4/5)(6/7)+...+((2/3)(4/5)...*38/39)
without using any loops only with vector calculations.

So my general approach is to create the sequence: z=1, 2/3 , 4/5 ...38/39
x=c(1,seq(2,38,2)) ; y=c(1,seq(3,39,2)) ; z=x/y

So I have my sequence z but now i want to create the original expresion meaning that each current term of z is the term multiplied with all each previous terms.To do that i wrote:
n=length(z) ; i=2:n
z[i]=z[i]*z[i-1]
but it doesn't work.Any ideas of how to approach this?

perhaps after you first calculate z then use that as input parameter to the cumulative product function cumprod()

1 Like

oh, I didn't know this command. Thank you this is exactly what I needed! I was basically trying to create my own cumprod command but without loops, I couldn't do it .

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.