0.2.0
Loading...
Searching...
No Matches
Math.hpp File Reference

Simple Math functions. More...

Go to the source code of this file.

Functions

double NAV::math::calcEllipticalIntegral (double phi, double m)
 Calculates the incomplete elliptical integral of the second kind.
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
NAV::math::csc (const T &x)
 Calculates the cosecant of a value (csc(x) = sec(pi/2 - x) = 1 / sin(x))
 
uint64_t NAV::math::factorial (uint64_t n)
 Calculates the factorial of an unsigned integer.
 
template<typename Out , size_t Bits, typename In , typename = std::enable_if_t<std::is_integral_v<Out>>, typename = std::enable_if_t<std::is_integral_v<In>>>
constexpr Out NAV::math::interpretAs (In in)
 Interprets the input integer with certain amount of Bits as Output type. Takes care of sign extension.
 
template<typename Derived >
Derived::PlainObject NAV::math::lerp (const Eigen::MatrixBase< Derived > &a, const Eigen::MatrixBase< Derived > &b, const typename Derived::Scalar &t)
 Linear interpolation between vectors.
 
template<typename Derived >
std::pair< Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime >, Eigen::Vector< typename Derived::Scalar, Derived::RowsAtCompileTime > > NAV::math::LtDLdecomp_choleskyFact (const Eigen::MatrixBase< Derived > &Q)
 Find (L^T D L)-decomposition of Q-matrix via a backward Cholesky factorization in a bordering method formulation.
 
template<typename Derived >
std::pair< Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime >, Eigen::Vector< typename Derived::Scalar, Derived::RowsAtCompileTime > > NAV::math::LtDLdecomp_outerProduct (const Eigen::MatrixBase< Derived > &Qmatrix)
 Find (L^T D L)-decomposition of Q-matrix via outer product method.
 
double NAV::math::normalCDF (double value)
 Calculates the cumulative distribution function (CDF) of the standard normal distribution.
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr T NAV::math::round (const T &value, size_t digits)
 Round the number to the specified amount of digits.
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr T NAV::math::roundSignificantDigits (T value, size_t digits)
 Round the number to the specified amount of significant digits.
 
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
NAV::math::sec (const T &x)
 Calculates the secant of a value (sec(x) = csc(pi/2 - x) = 1 / cos(x))
 
template<typename T >
int NAV::math::sgn (const T &val)
 Returns the sign of the given value.
 
template<typename T >
NAV::math::sign (const T &x, const T &y)
 Change the sign of x according to the value of y.
 
template<typename Derived >
Eigen::Matrix< typename Derived::Scalar, 3, 3 > NAV::math::skewSymmetricMatrix (const Eigen::MatrixBase< Derived > &a)
 Calculates the skew symmetric matrix of the given vector. This is needed to perform the cross product with a scalar product operation.
 
template<typename Derived >
Eigen::Matrix< typename Derived::Scalar, 3, 3 > NAV::math::skewSymmetricMatrixSquared (const Eigen::MatrixBase< Derived > &a)
 Calculates the square of a skew symmetric matrix of the given vector.
 
template<typename DerivedA , typename DerivedQ >
DerivedA::Scalar NAV::math::squaredNormVectorMatrix (const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedQ > &Q)
 Calculates the squared norm of the vector and matrix.
 

Detailed Description

Simple Math functions.

Author
T. Topp (topp@.nosp@m.ins..nosp@m.uni-s.nosp@m.tutt.nosp@m.gart..nosp@m.de)
N. Stahl (HiWi: Elliptical integral)
Date
2023-07-04

Function Documentation

◆ calcEllipticalIntegral()

double NAV::math::calcEllipticalIntegral ( double phi,
double m )

Calculates the incomplete elliptical integral of the second kind.

Parameters
[in]phiInterval bound the integration uses from 0 to phi
[in]mFunction parameter that is integrated 1-m*sin(t)^2
Returns
Incomplete elliptical integral of the second kind
Note
See http://www2.iap.fr/users/pichon/doc/html_xref/elliptic-es.html

◆ factorial()

uint64_t NAV::math::factorial ( uint64_t n)

Calculates the factorial of an unsigned integer.

Parameters
[in]nUnsigned integer
Returns
The factorial of 'n'

◆ interpretAs()

template<typename Out , size_t Bits, typename In , typename = std::enable_if_t<std::is_integral_v<Out>>, typename = std::enable_if_t<std::is_integral_v<In>>>
constexpr Out NAV::math::interpretAs ( In in)
constexpr

Interprets the input integer with certain amount of Bits as Output type. Takes care of sign extension.

Template Parameters
OutOutput type
BitsSize of the input data
InInput data type (needs to be bigger than the amount of Bits)
Parameters
[in]inNumber as two's complement, with the sign bit (+ or -) occupying the MSB
Returns
Output type

◆ lerp()

template<typename Derived >
Derived::PlainObject NAV::math::lerp ( const Eigen::MatrixBase< Derived > & a,
const Eigen::MatrixBase< Derived > & b,
const typename Derived::Scalar & t )

Linear interpolation between vectors.

Parameters
aLeft value
bRight value
tMultiplier. [0, 1] for interpolation
Returns
a + t * (b - a)

◆ LtDLdecomp_choleskyFact()

template<typename Derived >
std::pair< Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime >, Eigen::Vector< typename Derived::Scalar, Derived::RowsAtCompileTime > > NAV::math::LtDLdecomp_choleskyFact ( const Eigen::MatrixBase< Derived > & Q)

Find (L^T D L)-decomposition of Q-matrix via a backward Cholesky factorization in a bordering method formulation.

Parameters
[in]QSymmetric positive definite matrix to be factored
Returns
L - Factor matrix (strict lower triangular)
D - Vector with entries of the diagonal matrix
Note
See [12] de Jonge 1996, Algorithm FMFAC6

◆ LtDLdecomp_outerProduct()

template<typename Derived >
std::pair< Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime >, Eigen::Vector< typename Derived::Scalar, Derived::RowsAtCompileTime > > NAV::math::LtDLdecomp_outerProduct ( const Eigen::MatrixBase< Derived > & Qmatrix)

Find (L^T D L)-decomposition of Q-matrix via outer product method.

Parameters
[in]QmatrixSymmetric positive definite matrix to be factored
Returns
L - Factor matrix (strict lower triangular)
D - Vector with entries of the diagonal matrix
Note
See [12] de Jonge 1996, Algorithm FMFAC5
Attention
Consider using NAV::math::LtDLdecomp_choleskyFact() because it is faster by up to a factor 10

◆ normalCDF()

double NAV::math::normalCDF ( double value)

Calculates the cumulative distribution function (CDF) of the standard normal distribution.

\begin{equation} \label{eq:eq-normalDistCDF} \Phi(x) = \int\displaylimits_{-\infty}^x \frac{1}{\sqrt{2\pi}} \exp{\left(-\frac{1}{2} v^2\right)} \text{d}v \end{equation}

which can be expressed with the error function

\begin{equation} \label{eq:eq-normalDistCDF-erf} \Phi(x) = \frac{1}{2} \left[ 1 + \text{erf}{\left(\frac{x}{\sqrt{2}}\right)} \right] \end{equation}

Using the property

\begin{equation} \label{eq:eq-erf-minus} \text{erf}{\left( -x \right)} = -\text{erf}{\left( x \right)} \end{equation}

and the complementary error function

\begin{equation} \label{eq:eq-erfc} \text{erfc}{\left( x \right)} = 1 - \text{erf}{\left( x \right)} \end{equation}

we can simplify equation eq-normalDistCDF-erf to

\begin{equation} \label{eq:eq-normalDistCDF-erfc} \begin{aligned} \Phi(x) &= \frac{1}{2} \left[ 1 - \text{erf}{\left(-\frac{x}{\sqrt{2}}\right)} \right] \\ &= \frac{1}{2} \text{erfc}{\left(-\frac{x}{\sqrt{2}}\right)} \end{aligned} \end{equation}

Parameters
valueValue to calculate the CDF for

◆ round()

template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr T NAV::math::round ( const T & value,
size_t digits )
constexpr

Round the number to the specified amount of digits.

Parameters
[in]valueValue to round
[in]digitsAmount of digits
Returns
The rounded value

◆ roundSignificantDigits()

template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr T NAV::math::roundSignificantDigits ( T value,
size_t digits )
constexpr

Round the number to the specified amount of significant digits.

Parameters
[in]valueValue to round
[in]digitsAmount of digits
Returns
The rounded value

◆ sgn()

template<typename T >
int NAV::math::sgn ( const T & val)

Returns the sign of the given value.

Parameters
[in]valValue to get the sign from
Returns
Sign of the given value

◆ sign()

template<typename T >
T NAV::math::sign ( const T & x,
const T & y )

Change the sign of x according to the value of y.

Parameters
[in]xinput value
[in]yinput value
Returns
-x or +x

◆ skewSymmetricMatrix()

template<typename Derived >
Eigen::Matrix< typename Derived::Scalar, 3, 3 > NAV::math::skewSymmetricMatrix ( const Eigen::MatrixBase< Derived > & a)

Calculates the skew symmetric matrix of the given vector. This is needed to perform the cross product with a scalar product operation.

Template Parameters
DerivedDerived Eigen Type
Parameters
[in]aThe vector
Returns
Skew symmetric matrix
Note
See Groves (2013) equation (2.50)

◆ skewSymmetricMatrixSquared()

template<typename Derived >
Eigen::Matrix< typename Derived::Scalar, 3, 3 > NAV::math::skewSymmetricMatrixSquared ( const Eigen::MatrixBase< Derived > & a)

Calculates the square of a skew symmetric matrix of the given vector.

Template Parameters
DerivedDerived Eigen Type
Parameters
[in]aThe vector
Returns
Square of skew symmetric matrix

◆ squaredNormVectorMatrix()

template<typename DerivedA , typename DerivedQ >
DerivedA::Scalar NAV::math::squaredNormVectorMatrix ( const Eigen::MatrixBase< DerivedA > & a,
const Eigen::MatrixBase< DerivedQ > & Q )

Calculates the squared norm of the vector and matrix.

\begin{equation} \label{eq:eq-squaredNorm} ||\mathbf{\dots}||^2_{\mathbf{Q}} = (\dots)^T \mathbf{Q}^{-1} (\dots) \end{equation}

Parameters
aVector
QCovariance matrix of the vector
Returns
Squared norm