Friday, October 29, 2010

Quiz time: what does the following R code do?

Prize is brownie points.

y <- 7
z <- 1
y.last <- 0
while (abs(y.last-y)>1e-5) {
  y.last <- y
  y.temp <- 0.5*(y+1/z)
  z <- 0.5*(z+1/y)
  y <- y.temp
  print(y)
}