# Define the time of simulation maxTime <- 5 # 5 hours dt <- 0.1 # Precision of simulation # Prepare variable for results of simulation ts <- seq(0,maxTime,dt) N <- length(ts) # Number of samples x <- numeric( N ) # The results will go here # Run the simulation x[1] <- 0.2 # Initial condition for( i in 2:N ) { x[i] <- x[i-1] + dt*( -2 * x[i-1] + 1 ) } # Plot the results plot( ts, x, xlab = "Time (hours)", ylab = "Concentration (x)" )