Logistic Map

A logistic map simulation that iterates x_{n+1}=r*x_n*(1-x_n) to illustrate chaos.

Level:Advanced

populationnonlinear-dynamics

  • Stocks:x
  • Feedback Loops:growth with self-limiting term
  • Probes:x

Dynamic Behavior Patterns

Explore common system behaviors: exponential growth, goal-seeking decay, overshoot-and-collapse, and S-curve saturation.

Explore Dynamic Behavior Patterns
simulation.py

Exploring chaos with the logistic map

The logistic map follows the rule x_{n+1} = r * x_n * (1 - x_n). As we crank up the growth rate r the behaviour shifts from calm equilibrium, through period doubling, and eventually into chaos. Try a value near 3.5 to watch the system go wild.


from tys import probe, progress

Run the logistic map simulation.

def simulate(cfg: dict):

    import simpy
    env = simpy.Environment()

    r = cfg["growth_rate"]
    x = cfg["initial_value"]
    steps = cfg["steps"]

    done = env.event()

Iterate the map for the configured number of steps.

    def iterate():
        nonlocal x
        for i in range(steps):
            x = r * x * (1 - x)
            probe("x", env.now, x)
            yield env.timeout(1)
        progress(100)
        done.succeed({"final_x": x})

    env.process(iterate())
    env.run(until=done)
    return done.value


def requirements():
    return {
        "builtin": ["micropip", "pyyaml"],
        "external": ["simpy==4.1.1"],
    }
Default.yaml
initial_value: 0.4
growth_rate: 3.7
steps: 50
Charts (Default)

x

x chartCSV
Samples50 @ 0.00–49.00
Valuesmin 0.26, mean 0.66, median 0.72, max 0.92, σ 0.21
Final Results (Default)
MetricValue
final_x0.72
FAQ
How does the simulation produce chaotic behavior?
Iterating x = r * x * (1 - x) for high r values like 3.5 leads to period doubling and chaos.
How is the map iterated in SimPy?
The iterate process updates x and yields env.timeout(1) each step so time advances discretely.
What does the x probe capture?
It records the value after each iteration to show bifurcations over time.