Logistic Map

Iterates the logistic map x_{n+1}=r*x_n*(1-x_n) to illustrate chaotic dynamics.

Level:Advanced

chaosdiscretenonlinearbifurcation

  • 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"],
    }
config.yaml
initial_value: 0.4
growth_rate: 3.7
steps: 50