Build mathematical modelsLesson 39 of 48 · 9 min
Solve a decay equation
Solve a first-order ODE with an initial condition and verify it.
Maths refresher: Rate proportional to what remains
Exponential decay removes a constant fraction per unit time rather than a constant absolute amount.
For , the half-life is . Doubling doubles the trajectory but leaves that half-life unchanged.
An ordinary differential equation relates a function to its derivatives with respect to one independent variable. A decay law says the rate of change is proportional to the current amount, with a negative sign for loss.
SymPy Function represents the unknown function, and dsolve seeks a symbolic solution. An initial condition such as selects a member of the general solution family. Positive k makes this example decay as time increases.
Use checkodesol to substitute the returned function and its derivatives into the original differential equation. Also inspect the initial value. These mathematical checks do not establish that a constant decay rate is a suitable description of an actual population, stock or concentration.
Will a positive decay rate k make the solution grow or shrink for positive time?
Write a prediction (optional)
Exact solution of an authored decay model
Select Run Python with the code unchanged.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
Tools
About Python
Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗
Ctrl+Enter or ⌘+Enter runs Python.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
Worked text output
ODE: Eq(Derivative(N(t), t), -k*N(t)) Initial-value solution: Eq(N(t), N0*exp(-k*t)) ODE check: (True, 0) Initial value: N0 Half-life: log(2)/k Example half-life, seconds: 10*log(2) Example fraction at 5 seconds: exp(-1/2)
Read the starter result
The ODE check reports whether the solution satisfies the original equation. Initial value separately checks the condition at time zero. The example rows evaluate decay using an invented rate.
Edit and compare
Replace rate = sp.Rational(1,10) with rate = sp.Rational(1,5) to double the example decay rate. Select Run Python. Compare Example half-life, seconds and Example fraction at 5 seconds with the first run.
Scope. A first-order constant-rate model omits changing rates, external inputs and measurement uncertainty.
Try a fresh case
A general ODE solution contains an arbitrary constant. What typically selects a particular trajectory here?
Need a hint?
Hint 1
Many exponential curves satisfy the same proportional-rate law.
Hint 2
Identify which one passes through the specified starting point.