nlsq.core.functions.power_law

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

Power law function: y = a * x^b

Common for scaling relationships, fractals, allometry.

Parameters:
  • x (array_like) – Independent variable (must be positive)

  • a (float) – Prefactor (amplitude)

  • b (float) – Exponent (power)

Returns:

y – Dependent variable

Return type:

array_like

Notes

  • b > 0: increasing function (growth)

  • b < 0: decreasing function (decay)

  • b = 1: linear relationship

  • For x=1: y = a

Examples

>>> from nlsq import curve_fit
>>> from nlsq.core.functions import power_law
>>> import numpy as np
>>>
>>> # Allometric scaling: metabolic rate ∝ mass^0.75
>>> x = np.linspace(1, 100, 50)
>>> y = 3 * x**0.75 + np.random.normal(0, 0.5, 50)
>>> popt, pcov = curve_fit(power_law, x, y, p0='auto')
>>> print(f"Scaling exponent: {popt[1]:.2f}")