nlsq.core.functions.exponential_decay

nlsq.core.functions.exponential_decay(x, a, b, c)[source]

Exponential decay: y = a * exp(-b*x) + c

Common for radioactive decay, cooling curves, discharge curves.

Parameters:
  • x (array_like) – Independent variable (time, distance, etc.)

  • a (float) – Amplitude (initial value minus asymptote)

  • b (float) – Decay rate (positive, units: 1/x)

  • c (float) – Offset (asymptotic value as x → ∞)

Returns:

y – Dependent variable

Return type:

array_like

Notes

  • Half-life: t_half = ln(2) / b

  • Time constant: τ = 1 / b

  • At x=0: y = a + c

  • As x→∞: y → c

Examples

>>> from nlsq import curve_fit
>>> from nlsq.core.functions import exponential_decay
>>> import numpy as np
>>>
>>> # Radioactive decay with half-life = ln(2)/0.5 ≈ 1.4
>>> x = np.linspace(0, 10, 100)
>>> y = 100 * np.exp(-0.5 * x) + 10 + np.random.normal(0, 2, 100)
>>> popt, pcov = curve_fit(exponential_decay, x, y, p0='auto')
>>> print(f"Half-life: {np.log(2)/popt[1]:.2f}")