exp¶
- mdhelper.fit.exponential.exp(x: ndarray, *args: float) ndarray [source]¶
General exponential model.
- Parameters:
- xnumpy.ndarray
One-dimensional array containing
-values.- *argsfloat
Fitting parameters for the exponential term(s), ordered as
, where is the number of terms in the model. As such, the number of variable positional arguments must be even.
- Returns:
- fitnumpy.ndarray
Fitted
-values.
Examples
Generate
- and -values (with error), and then usescipy.optimize.curve_fit()
to fit coefficients for a two-term exponential model.>>> from scipy import optimize >>> rng = np.random.default_rng() >>> x = np.linspace(-0.1, 0.1, 10) >>> err = (2 * rng.random(x.shape) - 1) / 10 >>> y = np.exp(-8 * x) + np.exp(12 * x) + err >>> pk, _ = optimize.curve_fit( lambda x, a1, b1, a2, b2: exp(x, a1, b1, a2, b2), x, y ) >>> pk array([ 1.13072662, -6.90042351, 0.88706719, 12.87854508])
Evaluate the fitted
-values using the coefficients.>>> exp(x, *pk) array([2.49915084, 2.25973234, 2.09274413, 2.00061073, 1.98962716, 2.07080543, 2.26106343, 2.58486089, 3.07642312, 3.78274065])