Coding challenge

The logistic equation $x_{n+1} = r \cdot x_n \cdot (1 - x_n)$ is a simple model of population growth that exhibits the route from order to chaos as parameter $r$ changes.

Write a loop that starts at $x_0 = 0.5$ and iterates $100$ times. Try:

  1. $r = 2.8$: The sequence quickly settles onto a single fixed number.
  2. $r = 3.2$: The sequence alternates between 2 numbers (a period-2 cycle).
  3. $r = 3.9$: The sequence bounces around unpredictably forever in deterministic chaos!
Print the final value of $x$ for each case.

Type your code here:


Lua reference

See your results here: