rizer.kin.fit_arrhenius#
Attributes#
Functions#
|
Return the modified Arrhenius expression for the rate constant \(k\). |
|
Fit the rate constant k(T) with an modified Arrhenius expression using a least square fit. |
Module Contents#
- rizer.kin.fit_arrhenius.u#
- rizer.kin.fit_arrhenius.arrhenius_rate(A: float, b: float, Ea: float, T: float | numpy.ndarray) float | numpy.ndarray#
Return the modified Arrhenius expression for the rate constant \(k\).
The modified Arrhenius takes the form:
\[k(T) = A T^b exp(-\frac{E_a}{T})\]- Parameters:
A (
float) – Pre-exponential factor. Units could used one of (cm3, mol, s, K) / (m3, kmol, s, K) / …b (
float) – Temperature exponent [-].Ea (
float) – Activation energy [K].T (
float) – Temperature [K].
- Returns:
rate constant. - For first order reaction, it is in [s^-1]. - For second order reaction, it is in [cm3/(mol*s)] / [m^3/(kmol*s)] / … - For third order reaction, it is in [cm6/(mol^2*s)] / [m^6/(kmol^2*s)] / …
- Return type:
float
- rizer.kin.fit_arrhenius.k_fit_arrhenius_lstsq(k: numpy.ndarray, temperatures: numpy.ndarray, only_positive_activation_energy: bool = True, return_cost: bool = True) tuple[float, Ellipsis]#
Fit the rate constant k(T) with an modified Arrhenius expression using a least square fit.
The modified Arrhenius takes the form:
with:
\(k(T)\): rate constant [Could be (cm3, mol, s, K) / (m3, kmol, s, K) / …].
\(A\): pre-exponential factor [Same units as \(k\)].
\(b\): temperature exponent [-].
\(E_a\): activation energy [K].
\(T\): temperature [K].
- Parameters:
k (
np.ndarray) – Rate constant to be fitted. Units should be the same as the rate constant in the reaction.temperatures (
np.ndarray) – Temperatures at which the rate constant is computed, in Kelvin.only_positive_activation_energy (
bool, optional) – False if the activation energy can be negative, by default True.return_cost (
bool, optional) – True if the cost function value should be returned, by default True. It is the sum of the square of the residuals, divided by 2, with the residuals being the differenc between the fitted rate constant and the training data.
- Returns:
Fitted parameters A, b and Ea. Units of A are the same as the rate constant in the reaction. b is dimensionless. Ea is in K. If return_cost is True, the cost function value is also returned.
- Return type:
tuple[float,float,float]ortuple[float,float,float,float]- Raises:
ValueError – If the least square optimization failed.
Notes
The function fits the rate constant k(T) with an modified Arrhenius expression using a least square fit.
For more accuracy, the logarithm of the rate constant is used:
\[log(k(T)) = log(A) + b \cdot log(T) - \frac{E_a}{T}\]For further clarification, this function calls [scipy.optimize.lsq_linear](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.lsq_linear.html) to perform a linear least squares fit with bounds on the parameters.
The system to solve is:
\[minimize 0.5 * ||A x - b||**2 subject to lb <= x <= ub\]The matrix A is defined as:
\[\begin{split}A = \begin{bmatrix} 1 & log(T_1) & -\frac{1}{T_1} \\ 1 & log(T_2) & -\frac{1}{T_2} \\ \vdots & \vdots & \vdots \\ 1 & log(T_n) & -\frac{1}{T_n} \end{bmatrix}\end{split}\]The vector b is defined as:
\[\begin{split}b = \begin{bmatrix} log(k_1) \\ log(k_2) \\ \vdots \\ log(k_n) \end{bmatrix}\end{split}\]The vector of fitted parameters x is defined as:
\[\begin{split}x = \begin{bmatrix} log(A) \\ b \\ -\frac{E_a}{T} \end{bmatrix}\end{split}\]The bounds on the parameters are defined as:
If only_positive_activation_energy is True:
\[\begin{split}\begin{align*} -\infty &\leq log(A) \leq \infty \\ -\infty &\leq b \leq \infty \\ 0 &\leq E_a \leq \infty \end{align*}\end{split}\]If only_positive_activation_energy is False:
\[\begin{split}\begin{align*} -\infty &\leq log(A) \leq \infty \\ -\infty &\leq b \leq \infty \\ -\infty &\leq E_a \leq \infty \end{align*}\end{split}\]Once solved, the fitted parameters (log(A), b, -E_a) are extracted and converted to A, b and Ea.
The function returns these parameters, i.e. A, b and Ea.
If return_cost is True, the cost function value is also returned. The cost function is defined as the sum of the square of the residuals, divided by 2. The residuals are the difference between the fitted rate constant and the training data.
\[cost = 0.5 * ||A x_lsq - b||**2\]where x_lsq are the fitted parameters and b is the training data.