neutronpy.functions.lorentzian

neutronpy.functions.lorentzian(p, q)[source]

Returns an arbitrary number of Lorentz profiles.

Parameters:
p : ndarray

Parameters for the Lorentzian, in the following format:

p[0] Constant background
p[1] Linear background slope
p[2] Area under the first peak
p[3] Position of the first peak
p[4] FWHM of the first peak
p[5] Area under the second peak
p[…] etc.
q : ndarray

One dimensional input array.

Returns:
out : ndarray

One dimensional Lorentzian profile.

Notes

A Lorentzian profile is defined as:

\[f(q) = \frac{a}{\pi} \frac{\frac{1}{2} \Gamma}{(q-q_0)^2 + (\frac{1}{2} \Gamma)^2},\]

where the integral over the whole function is a, and Γ is the full width at half maximum.

Examples

Plot a single lorentzian with an integrated intensity of 1, centered at zero, and fwhm of 0.3:

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> p = np.array([0., 0., 1., 0., 0.3])
>>> x = np.linspace(-1, 1, 101)
>>> y = lorentzian(p, x)
>>> plt.plot(x, y)
>>> plt.show()

Plot two lorentzians, equidistant from the origin with the same intensity and fwhm as above:

>>> p = np.array([0., 0., 1., -0.3, 0.3, 1., 0.3, 0.3])
>>> x = np.linspace(-1, 1, 101)
>>> y = lorentzian(p, x)
>>> plt.plot(x, y)
>>> plt.show()