Lesson 5 of 15

Exponential Decay

Exponential Decay

The simplest real-world ODE:

dydt=ky,y(0)=y0\frac{dy}{dt} = -k \cdot y, \quad y(0) = y_0

The rate of change is proportional to the current value. The exact solution is:

y(t)=y0ekty(t) = y_0 \cdot e^{-kt}

Applications

  • Radioactive decay: atoms decay at a rate proportional to their count
  • Drug clearance: concentration in blood decreases proportionally
  • Capacitor discharge: voltage drops exponentially
  • Population decline: a species dying off at a fixed rate

Half-Life

The half-life is the time for yy to reach half its initial value:

y02=y0ekthalf    thalf=ln2k0.693k\frac{y_0}{2} = y_0 \cdot e^{-k \cdot t_{\text{half}}} \implies t_{\text{half}} = \frac{\ln 2}{k} \approx \frac{0.693}{k}

Numerical Solution

Using Euler's method with nn steps:

def exponential_decay(k, y0, t_end, n):
    h = t_end / n
    y = float(y0)
    for _ in range(n):
        y = y + h * (-k * y)
    return y

Your Task

Implement exponential_decay(k, y0, t_end, n) that numerically solves dydt=ky\frac{dy}{dt} = -k \cdot y and returns the final value y(tend)y(t_{\text{end}}).

Pyodide loading...
Loading...
Click "Run" to execute your code.