[R] dynamics of functions
Hotz, T.
th50 at leicester.ac.uk
Thu Jun 5 17:33:42 CEST 2003
Dear Tobias,
> I would like to study the dynamics of
> functions using R (instead of mathematica e.g.),
> i.e. the behavior of points under iteration
> of a function.
> So I tried (in vain) writing a function
> myfunction <- function(f,n,x){...}
> in order to compute f^{n}(x), f^{n}(x) being
> the function f composed with itself n-1 times.
> n is a natural number, and the argument x is
> the abscissa of the point I would like to
> `follow'.
What about the following function?
iterate<-function(f,n,x){
if(n==0) return(x)
y<-x
for(i in 1:n)y<-f(y)
y
}
iterate(sqrt,3,256)
Hope that helps.
Best wishes
Thomas
---
Thomas Hotz
Research Associate in Medical Statistics
University of Leicester
United Kingdom
Department of Epidemiology and Public Health
22-28 Princess Road West
Leicester
LE1 6TP
Tel +44 116 252-5410
Fax +44 116 252-5423
Division of Medicine for the Elderly
Department of Medicine
The Glenfield Hospital
Leicester
LE3 9QP
Tel +44 116 256-3643
Fax +44 116 232-2976
More information about the R-help
mailing list