Composing two functions in R gives different result than a new function enclosing both

54 views Asked by At

I tried to look at the logistic map

logMap <- function(x){
r <- 0.5
4*r*x*(1-x)}

and its compositions such as:

logMap2_a <- function(x){
  logMap(logMap(x))}

Of course, you can also directly write a new function that composes logMap with itself:

logMap2 <- function(x){
r <- 0.5
16*r*r*x*(1-x)*(1-16*r*r*x*(1-x))}

Now, plotting the two things does not show the same curve:

curve(logMap2, from=0, to=1)
curve(logMap2_a, from=0, to=1)

The first figure shows the result of logMap2, the second that of logMap2_a.

This is the picture I wanted to have, the power of two of the logistic map (function logMap2)

This is the curve of the composition which should yield the same curve as the power of two of the logistic map (function logMap2_a)

My first idea was that the problem arises due to the precision of returned data, but I cannot imagine that this is a problem with this reasonably large numbers. Any idea what is going on?

1

There are 1 answers

0
Nick Kennedy On
logMap2 <- function(x){
r <- 0.5
16*r*r*x*(1-x)*(1-4*r*x*(1-x))}