Stan Math Library  2.20.0
reverse mode automatic differentiation
matrix_exp_pade.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_MATRIX_EXP_PADE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_MATRIX_EXP_PADE_HPP
3 
4 #include <stan/math/prim/mat/fun/MatrixExponential.h>
5 
6 namespace stan {
7 namespace math {
8 
19 template <typename MatrixType>
20 MatrixType matrix_exp_pade(const MatrixType& arg) {
21  MatrixType U, V;
22  int squarings;
23  Eigen::matrix_exp_computeUV<MatrixType>::run(arg, U, V, squarings, arg(0, 0));
24  // Pade approximant is
25  // (U+V) / (-U+V)
26  MatrixType numer = U + V;
27  MatrixType denom = -U + V;
28  MatrixType pade_approximation = denom.partialPivLu().solve(numer);
29  for (int i = 0; i < squarings; ++i)
30  pade_approximation *= pade_approximation; // undo scaling by
31  // repeated squaring
32  return pade_approximation;
33 }
34 } // namespace math
35 } // namespace stan
36 #endif
MatrixType matrix_exp_pade(const MatrixType &arg)
Computes the matrix exponential, using a Pade approximation, coupled with scaling and squaring...

     [ Stan Home Page ] © 2011–2018, Stan Development Team.