Cantera
3.0.0
|
Collection of numerical utility functions for integration, interpolation and data fitting. More...
Collection of numerical utility functions for integration, interpolation and data fitting.
Functions | |
double | linearInterp (double x, const vector< double > &xpts, const vector< double > &fpts) |
Linearly interpolate a function defined on a discrete grid. | |
double | trapezoidal (const Eigen::ArrayXd &f, const Eigen::ArrayXd &x) |
Numerical integration of a function using the trapezoidal rule. | |
double | simpson (const Eigen::ArrayXd &f, const Eigen::ArrayXd &x) |
Numerical integration of a function using Simpson's rule with flexibility of taking odd and even number of points. | |
double | numericalQuadrature (const string &method, const Eigen::ArrayXd &f, const Eigen::ArrayXd &x) |
Numerical integration of a function. | |
double | polyfit (size_t n, size_t deg, const double *x, const double *y, const double *w, double *p) |
Fits a polynomial function to a set of data points. | |
double linearInterp | ( | double | x, |
const vector< double > & | xpts, | ||
const vector< double > & | fpts | ||
) |
Linearly interpolate a function defined on a discrete grid.
Vector xpts contains a monotonic sequence of grid points, and vector fpts contains function values defined at these points. The value returned is the linear interpolate at point x. If x is outside the range of xpts, the value of fpts at the nearest end is returned.
x | value of the x coordinate |
xpts | value of the grid points |
fpts | value of the interpolant at the grid points |
double trapezoidal | ( | const Eigen::ArrayXd & | f, |
const Eigen::ArrayXd & | x | ||
) |
Numerical integration of a function using the trapezoidal rule.
Vector x contains a monotonic sequence of grid points, and Vector f contains function values defined at these points. The size of x and f must be the same.
f | vector of function value |
x | vector of function coordinate |
double simpson | ( | const Eigen::ArrayXd & | f, |
const Eigen::ArrayXd & | x | ||
) |
Numerical integration of a function using Simpson's rule with flexibility of taking odd and even number of points.
For even number, Simpson's rule is used for the first N-2 intervals with a trapezoidal rule on the last interval.
Vector x contains a monotonic sequence of grid points, and Vector f contains function values defined at these points. The size of x and f must be the same.
f | vector of function value |
x | vector of function coordinate |
double numericalQuadrature | ( | const string & | method, |
const Eigen::ArrayXd & | f, | ||
const Eigen::ArrayXd & | x | ||
) |
Numerical integration of a function.
Vector x contains a monotonic sequence of grid points, and Vector f contains function values defined at these points. The size of x and f must be the same.
method | method name |
f | vector of function value |
x | vector of function coordinate |
double polyfit | ( | size_t | n, |
size_t | deg, | ||
const double * | x, | ||
const double * | y, | ||
const double * | w, | ||
double * | p | ||
) |
Fits a polynomial function to a set of data points.
Given a collection of n points x and a set of values y of some function evaluated at those points, this function computes the weighted least-squares polynomial fit of degree deg:
\[ f(x) = p[0] + p[1] x + p[2] x^2 + \cdots + p[deg] x^deg \]
n | The number of points at which the function is evaluated | |
deg | The degree of the polynomial fit to be computed. deg <= n - 1. | |
x | Array of points at which the function is evaluated. Length n. | |
y | Array of function values at the points in x. Length n. | |
w | Array of weights. If w == nullptr or w[0] < 0, then all the weights will be set to 1.0. | |
[out] | p | Array of polynomial coefficients, starting with the constant term. Length deg+1. |
Definition at line 14 of file polyfit.cpp.