Change the value of r (a positive number representing the growth
rate) in the value section to create a different behavioural
system.
# Load packages
pacman::p_load(pacman,tidyverse,GGally,ggthemes,ggplot2,ggvis,httr,plotly,rio,rmarkdown,shiny,rgl)
logistic_map <- function(r, x0, iterations) {
values <- numeric(iterations)
x <- x0
for (i in 1:iterations) {
x <- r * x * (1 - x)
values[i] <- x
}
return(values)
}
write_to_csv <- function(sequence, filename) {
write.csv(data.frame(value=sequence), file=filename, row.names=FALSE)
}
# You can adjust the r, x0, and iterations values in the "Value section"
# section to generate different sequences.
# For instance, by changing r to values like 2 or 3.5 or 3.57 or 3.89 or 3.99
# you can observe different behaviours of the system.
# Value section
r <- 3.57 # 2, 3, 3.5, 3.89, 3.99 were also used to create the uploaded csv files.
x0 <- 0.5 # is a number between 0 and 1, representing the ratio of the existing population to the maximum possible population. For example 0.5 (i.e., half the maximum population).
iterations <- 100 # Number of repetitions.
sequence <- logistic_map(r, x0, iterations)
write_to_csv(sequence, "logistic_map_r=3.57.csv") # Alter csv file value for r
# to match r in the value section.
# To prevent overwriting.