Ember
|
A collection of general-purpose mathematical functions for working with vectors. More...
Functions | |
double | maxval (const dvector &v) |
Returns the value of the maximum element of a vector. | |
double | minval (const dvector &v) |
Returns the value of the minimum element of a vector. | |
double | range (const dvector &v) |
Returns the range (maximum - minimum) of a vector. | |
double | sum (const dvector &v) |
Returns the sum of all the elements in a vector. | |
double | mean (const dvector &v) |
Returns the arithemetic mean of the elements in a vector. | |
double | maxval (const dvector &v, size_t iStart, size_t iEnd) |
Returns the value of the maximum element of the sub-vector of v with indices on the closed interval [iStart, iEnd] | |
double | minval (const dvector &v, size_t iStart, size_t iEnd) |
Returns the value of the minimum element of the sub-vector of v with indices on the closed interval [iStart, iEnd] | |
double | range (const dvector &v, size_t iStart, size_t iEnd) |
Returns the range (maximum - minimum) of the sub-vector of v with indices on the closed interval [iStart, iEnd] | |
double | sum (const dvector &v, size_t iStart, size_t iEnd) |
Returns the sum of all the elements in the sub-vector of v with indices on the closed interval [iStart, iEnd] | |
double | mean (const dvector &v, size_t iStart, size_t iEnd) |
Returns the arithemetic mean of the sub-vector of v with indices on the closed interval [iStart, iEnd] | |
size_t | minloc (const dvector &v) |
Returns the index of the minimum element of v. | |
size_t | maxloc (const dvector &v) |
Returns the index of the maximum element of v. | |
template<typename Derived > | |
bool | notnan (const Eigen::EigenBase< Derived > &v) |
Returns true if v does not contain any NaN s. | |
template<typename T > | |
bool | notnan (const vector< T > &v) |
Returns true if v does not contain any NaN s. | |
bool | notnan (const double &v) |
Returns true if v is not NaN . | |
bool | notnan (const sdVector &v) |
Returns true if v does not contain any NaN s. | |
size_t | nanloc (const dvector &v) |
Returns the index of first NaN component of v . | |
bool | almostEqual (double a, double b, double rtol=1e-10, double atol=1e-18) |
Returns true if a and b are equal to within the specified relative (rtol ) and absolute (atol ) tolerances. | |
dvector | abs (const dvector &v) |
Returns a vector containing the absolute values of the elements of v. | |
template<class T > | |
int | findFirst (const T &v) |
Returns the index of the first element of v which is true . | |
template<class T > | |
int | findLast (const T &v) |
Returns the index of the last element of v which is true . | |
vector< int > | find (vector< bool > &v) |
Returns a vector containing the indices of the elements of v which are true . | |
template<class T > | |
void | smooth (T &v) |
Applies a simple smoothing function to v which effectively filters out high-frequency components. | |
dvector | linspace (const double x1, const double x2, const int n) |
Returns a vector of n elements linearly spaced along the closed interval [x1, x2] | |
template<class T1 , class T2 > | |
vector< T1 > | computeSplines (const T1 &xIn, const T2 &yIn) |
Internal function for calculating cubic splines for a sequence of data points. | |
template<class T > | |
T | interp1 (const T &xIn, const T &yIn, const T &xOut, bool extrap=true) |
Linear interpolation for a vector of desired outputs. | |
template<class T > | |
double | interp1 (const T &xIn, const T &yIn, const double xOut, bool extrap=true) |
Linear interpolation for a single output point. | |
dvec | splines (const dvec &xIn, const dvec &yIn, const dvec &xOut) |
Cubic spline interpolation for a vector of desired outputs. | |
double | splines (const dvec &xIn, const dvec &yIn, const double xOut) |
Cubic spline interpolation for a single output point. | |
template<class T1 , class T2 > | |
double | integrate (const T1 &x, const T2 &y) |
Numerical integration using the cubic spline fit for the given data. | |
template<class T1 , class T2 > | |
double | trapz (const T1 &x, const T2 &y) |
Trapezoidal rule integration. | |
void | vectorVectorToArray2D (const vector< dvector > &v, dmatrix &a) |
void | array2DToVectorVector (const dmatrix &a, vector< dvector > &v) |
std::string | stringify (double x) |
std::string | stringify (double x, int nDigits) |
std::string | stringify (int x) |
int | sign (const double x) |
int | sign (const int x) |
template<class Tx , class Ty > | |
void | uniqueSort (vector< Tx > &keys, vector< vector< Ty > > &values) |
Sort & remove duplicate entries from keys, and perform the same permutation on values Requires that keys.size() == values[i].size() | |
A collection of general-purpose mathematical functions for working with vectors.
double mathUtils::maxval | ( | const dvector & | v | ) |
Returns the value of the maximum element of a vector.
double mathUtils::minval | ( | const dvector & | v | ) |
Returns the value of the minimum element of a vector.
double mathUtils::range | ( | const dvector & | v | ) |
Returns the range (maximum - minimum) of a vector.
double mathUtils::sum | ( | const dvector & | v | ) |
Returns the sum of all the elements in a vector.
double mathUtils::mean | ( | const dvector & | v | ) |
Returns the arithemetic mean of the elements in a vector.
double mathUtils::maxval | ( | const dvector & | v, |
size_t | iStart, | ||
size_t | iEnd | ||
) |
Returns the value of the maximum element of the sub-vector of v with indices on the closed interval [iStart, iEnd]
double mathUtils::minval | ( | const dvector & | v, |
size_t | iStart, | ||
size_t | iEnd | ||
) |
Returns the value of the minimum element of the sub-vector of v with indices on the closed interval [iStart, iEnd]
double mathUtils::range | ( | const dvector & | v, |
size_t | iStart, | ||
size_t | iEnd | ||
) |
Returns the range (maximum - minimum) of the sub-vector of v with indices on the closed interval [iStart, iEnd]
double mathUtils::sum | ( | const dvector & | v, |
size_t | iStart, | ||
size_t | iEnd | ||
) |
Returns the sum of all the elements in the sub-vector of v with indices on the closed interval [iStart, iEnd]
double mathUtils::mean | ( | const dvector & | v, |
size_t | iStart, | ||
size_t | iEnd | ||
) |
Returns the arithemetic mean of the sub-vector of v with indices on the closed interval [iStart, iEnd]
size_t mathUtils::minloc | ( | const dvector & | v | ) |
Returns the index of the minimum element of v.
size_t mathUtils::maxloc | ( | const dvector & | v | ) |
Returns the index of the maximum element of v.
bool mathUtils::notnan | ( | const Eigen::EigenBase< Derived > & | v | ) |
Returns true if v
does not contain any NaN
s.
bool mathUtils::notnan | ( | const vector< T > & | v | ) |
Returns true if v
does not contain any NaN
s.
|
inline |
Returns true if v
is not NaN
.
bool mathUtils::notnan | ( | const sdVector & | v | ) |
Returns true if v
does not contain any NaN
s.
size_t mathUtils::nanloc | ( | const dvector & | v | ) |
Returns the index of first NaN
component of v
.
Returns -1 if no elements are NaN
.
|
inline |
Returns true
if a and b are equal to within the specified relative (rtol
) and absolute (atol
) tolerances.
Returns a vector containing the absolute values of the elements of v.
int mathUtils::findFirst | ( | const T & | v | ) |
Returns the index of the first element of v which is true
.
Returns -1
if all elements of v are false
.
int mathUtils::findLast | ( | const T & | v | ) |
Returns the index of the last element of v which is true
.
Returns -1
if all elements of v are false
.
vector< int > mathUtils::find | ( | vector< bool > & | v | ) |
Returns a vector containing the indices of the elements of v which are true
.
void mathUtils::smooth | ( | T & | v | ) |
Applies a simple smoothing function to v which effectively filters out high-frequency components.
dvector mathUtils::linspace | ( | const double | x1, |
const double | x2, | ||
const int | n | ||
) |
Returns a vector of n elements linearly spaced along the closed interval [x1, x2]
vector< T1 > mathUtils::computeSplines | ( | const T1 & | xIn, |
const T2 & | yIn | ||
) |
Internal function for calculating cubic splines for a sequence of data points.
T mathUtils::interp1 | ( | const T & | xIn, |
const T & | yIn, | ||
const T & | xOut, | ||
bool | extrap = true |
||
) |
Linear interpolation for a vector of desired outputs.
T
is a container of doubles, e.g. vector<double>
or Eigen::ArrayXd
.
xIn | Input x-coordinates, length N. Must be monotonically increasing. |
yIn | Input y-coordinates, length N |
xOut | Target x-coordinates, length M |
extrap | Linearly extrapolate outside the input interval. If false, clip to the nearest value. |
double mathUtils::interp1 | ( | const T & | xIn, |
const T & | yIn, | ||
const double | xOut, | ||
bool | extrap = true |
||
) |
Linear interpolation for a single output point.
T
is a container of dobules, e.g. vector<double>
or Eigen::ArrayXd
.
xIn | Input x-coordinates, length N. Must be monotonically increasing. |
yIn | Input y-coordinates, length N |
xOut | Target x-coordinate |
extrap | Linearly extrapolate outside the input interval. If false, clip to the nearest value. |
Cubic spline interpolation for a vector of desired outputs.
xIn | Input x-coordinates, length N. Must be monotonically increasing. |
yIn | Input y-coordinates, length N |
xOut | Target x-coordinates, length M |
Cubic spline interpolation for a single output point.
xIn | Input x-coordinates, length N. Must be monotonically increasing. |
yIn | Input y-coordinates, length N |
xOut | Target x-coordinate |
double mathUtils::integrate | ( | const T1 & | x, |
const T2 & | y | ||
) |
Numerical integration using the cubic spline fit for the given data.
double mathUtils::trapz | ( | const T1 & | x, |
const T2 & | y | ||
) |
Trapezoidal rule integration.
std::string mathUtils::stringify | ( | double | x | ) |
std::string mathUtils::stringify | ( | double | x, |
int | nDigits | ||
) |
std::string mathUtils::stringify | ( | int | x | ) |
int mathUtils::sign | ( | const double | x | ) |
int mathUtils::sign | ( | const int | x | ) |
void mathUtils::uniqueSort | ( | vector< Tx > & | keys, |
vector< vector< Ty > > & | values | ||
) |
Sort & remove duplicate entries from keys, and perform the same permutation on values Requires that keys.size() == values[i].size()