Goal-Seeking Decay

First-order exponential approach toward a goal level, such as medication elimination.

Level:Beginner

decaygoalbalancingexponentialcontrol

  • Stocks:level
  • Flows:approach_rate
  • Feedback Loops:goal-seeking (balancing)
  • Probes:level, approach_rate

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

Chasing a goal with exponential decay

This little demo walks through a feedback loop that nudges a value toward a target. Each step closes a fraction k of the gap, so the closer we get the slower we move.


from tys import probe, progress

Run the goal-seeking decay simulation.

def simulate(cfg: dict):

    import simpy

    env = simpy.Environment()

    level = cfg["initial_level"]
    goal = cfg["goal_level"]
    k = cfg["rate_constant"]
    steps = cfg["steps"]

    done = env.event()

Evolve the level toward the goal each step.

    def run():
        nonlocal level
        for i in range(steps):
            change = k * (goal - level)
            level += change
            probe("level", env.now, level)
            probe("approach_rate", env.now, change)
            yield env.timeout(1)
        progress(100)
        done.succeed({"final_level": level})

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


def requirements():
    return {
        "builtin": ["micropip", "pyyaml"],
        "external": ["simpy==4.1.1"],
    }
config.yaml
initial_level: 100
goal_level: 0
rate_constant: 0.1
steps: 50