Cantera  3.1.0a1
Numerical Integration and Interpolation

Collection of numerical utility functions for integration, interpolation and data fitting. More...

Collaboration diagram for Numerical Integration and Interpolation:

Detailed Description

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. More...
 
double trapezoidal (const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
 Numerical integration of a function using the trapezoidal rule. More...
 
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. More...
 
double numericalQuadrature (const string &method, const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
 Numerical integration of a function. More...
 
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. More...
 

Function Documentation

◆ linearInterp()

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.

Parameters
xvalue of the x coordinate
xptsvalue of the grid points
fptsvalue of the interpolant at the grid points
Returns
the value of of the interpolated function at x.

Definition at line 13 of file funcs.cpp.

◆ trapezoidal()

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.

Parameters
fvector of function value
xvector of function coordinate

Definition at line 29 of file funcs.cpp.

◆ simpson()

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.

Parameters
fvector of function value
xvector of function coordinate

Definition at line 87 of file funcs.cpp.

◆ numericalQuadrature()

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.

Parameters
methodmethod name
fvector of function value
xvector of function coordinate

Definition at line 112 of file funcs.cpp.

◆ polyfit()

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 \]

Parameters
nThe number of points at which the function is evaluated
degThe degree of the polynomial fit to be computed. deg <= n - 1.
xArray of points at which the function is evaluated. Length n.
yArray of function values at the points in x. Length n.
wArray of weights. If w == nullptr or w[0] < 0, then all the weights will be set to 1.0.
[out]pArray of polynomial coefficients, starting with the constant term. Length deg+1.
Returns
the root mean squared error of the fit at the input points.

Definition at line 14 of file polyfit.cpp.