The R Project SVN R

Rev

Rev 70394 | Rev 81157 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 70394 Rev 74363
Line 124... Line 124...
124
## Continued fraction approximation for Euler's number (e):
124
## Continued fraction approximation for Euler's number (e):
125
cfrac(c(2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8))
125
cfrac(c(2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8))
126
 
126
 
127
## Iterative function application:
127
## Iterative function application:
128
Funcall <- function(f, ...) f(...)
128
Funcall <- function(f, ...) f(...)
129
## Compute log(exp(acos(cos(0))
129
## Compute log(exp(acos(cos(0))))
130
Reduce(Funcall, list(log, exp, acos, cos), 0, right = TRUE)
130
Reduce(Funcall, list(log, exp, acos, cos), 0, right = TRUE)
131
## n-fold iterate of a function, functional style:
131
## n-fold iterate of a function, functional style:
132
Iterate <- function(f, n = 1)
132
Iterate <- function(f, n = 1)
133
    function(x) Reduce(Funcall, rep.int(list(f), n), x, right = TRUE)
133
    function(x) Reduce(Funcall, rep.int(list(f), n), x, right = TRUE)
134
## Continued fraction approximation to the golden ratio:
134
## Continued fraction approximation to the golden ratio: