Note
Go to the end to download the full example code.
Power law: vacuum diode#
In a vacuum diode, the space-charge limited anode current follows the Child–Langmuir law I = k · U^(3/2). Fitting a general power law tests whether the exponent really is 3/2.
import numpy as np
import fitwise as fw
rng = np.random.default_rng(10)
voltage = np.linspace(10, 200, 25) # V
current = 0.018 * voltage**1.5 * (1 + rng.normal(0, 0.02, voltage.size)) # mA
dI = 0.02 * current
result = fw.fit(fw.models.powerlaw, voltage, current, yerr=dI)
print(result)
Model: powerlaw(x; amp, exponent)
Method: Trust Region Reflective (scipy least_squares) (auto: nonlinear)
Converged: yes (14 evals)
Data: 25 points, yerr given (absolute)
Start: amp, exponent: log-log fit
Parameter Value ± Std.Err Rel. Bounds
amp 0.01786 0.00041 2.3 % –
exponent 1.5002 0.0051 0.3 % –
χ²/ndf = 0.532 (23 dof, p = 0.97) R² = 0.99976 AIC = -13.9
Correlations > 0.5: amp–exponent (-0.98)
Warnings: none
Is the exponent compatible with 3/2?
exponent = 1.5002 ± 0.0051, deviation from 1.5: +0.0 σ
If theory fixes the exponent, fix it and fit only the prefactor:
Model: powerlaw(x; amp, exponent)
Method: Trust Region Reflective (scipy least_squares) (auto: nonlinear)
Converged: yes (11 evals)
Data: 25 points, yerr given (absolute)
Start: amp: log-log fit · exponent: fixed
Parameter Value ± Std.Err Rel. Bounds
amp 0.017871 0.000071 0.4 % –
exponent 1.5 – – fixed
χ²/ndf = 0.51 (24 dof, p = 0.98) R² = 0.99976 AIC = -15.9
Warnings: none

Text(0.5, 18.503588541666673, 'U (V)')
Total running time of the script: (0 minutes 0.182 seconds)