Skip to content
Prev 154894 / 398503 Next

optimizing speed of calculation (recursive product)

Wolfgang Raffelsberger wrote:
Well, in principal you could say:

a <- runif(10000000,0.5,1.6)
C <- 2
M <- 10000000
system.time(C <- C * c(prod(a[-M]), prod(a[-1])))

but this is all completely inaccurate from a numerical point of view - 
and you probably end up with c(0, 0) which is the quickest way to 
calculate those numbers in similar accurate way.

Uwe Ligges