nlsq.core.functions.gaussian¶
- nlsq.core.functions.gaussian(x, amp, mu, sigma)[source]¶
Gaussian (normal distribution) function: y = amp * exp(-(x-mu)² / (2*sigma²))
Common for spectral peaks, chromatography peaks, probability distributions.
- Parameters:
- Returns:
y – Dependent variable
- Return type:
array_like
Notes
Peak position: x = mu
Peak height: y = amp
FWHM (Full Width at Half Maximum): FWHM = 2.355 * sigma
Integral: ∫ gaussian dx = amp * sigma * sqrt(2π)
Examples
>>> from nlsq import curve_fit >>> from nlsq.core.functions import gaussian >>> import numpy as np >>> >>> # Spectral peak at x=5 with FWHM ≈ 2.355 >>> x = np.linspace(0, 10, 200) >>> y = 10 * np.exp(-(x-5)**2 / (2*1**2)) + np.random.normal(0, 0.2, 200) >>> popt, pcov = curve_fit(gaussian, x, y, p0='auto') >>> print(f"Peak at {popt[1]:.2f}, FWHM = {2.355*popt[2]:.2f}")