nlsq.core.functions.lorentzian¶
- nlsq.core.functions.lorentzian(x, amp, x0, gamma)[source]¶
Lorentzian (Cauchy) peak function: y = amp / (1 + ((x - x0) / gamma)²)
Common for spectral line shapes (NMR, IR, Raman), resonance curves, and natural line broadening.
- Parameters:
- Returns:
y – Dependent variable
- Return type:
array_like
Notes
Peak position: x = x0
Peak height: y = amp
FWHM (Full Width at Half Maximum): FWHM = 2 * gamma
Integral: ∫ lorentzian dx = amp * gamma * π
Heavier tails than Gaussian (decays as 1/x² vs exp(-x²))
Examples
>>> from nlsq import curve_fit >>> from nlsq.core.functions import lorentzian >>> import numpy as np >>> >>> # Spectral peak at x=5 with FWHM = 2 >>> x = np.linspace(0, 10, 200) >>> y = 10 / (1 + ((x - 5) / 1)**2) + np.random.normal(0, 0.2, 200) >>> popt, pcov = curve_fit(lorentzian, x, y, p0='auto') >>> print(f"Peak at {popt[1]:.2f}, FWHM = {2*popt[2]:.2f}")