I am writing a function for Ramanujan nested radicals in R. Ramanujan nested radicals equation is following:
I need to take n as only input argument. I am not sure how to code it in R.
I think this should do it
RNR <- function(N) Reduce(function(n, x) sqrt(1 + n * x), 2:N, 1, right = TRUE)
sapply(2:10, RNR) #only valid for N>1
[1] 1.732051 2.236068 2.559830 2.755053 2.867103 2.929173 2.962723 2.980554 2.989920