11#ifndef EIGEN_MATRIX_EXPONENTIAL
12#define EIGEN_MATRIX_EXPONENTIAL
26template <
typename RealScalar>
38 inline const RealScalar
operator()(
const RealScalar& x)
const {
40 return ldexp(x, -m_squarings);
51 return ComplexScalar(ldexp(x.real(), -m_squarings), ldexp(x.imag(), -m_squarings));
63template <
typename MatA,
typename MatU,
typename MatV>
65 typedef typename MatA::PlainObject MatrixType;
66 typedef typename NumTraits<typename traits<MatA>::Scalar>::Real RealScalar;
67 const RealScalar
b[] = {120.L, 60.L, 12.L, 1.L};
68 const MatrixType A2 = A * A;
69 const MatrixType tmp =
b[3] * A2 +
b[1] * MatrixType::Identity(A.rows(), A.cols());
70 U.noalias() = A * tmp;
71 V =
b[2] * A2 +
b[0] * MatrixType::Identity(A.rows(), A.cols());
79template <
typename MatA,
typename MatU,
typename MatV>
81 typedef typename MatA::PlainObject MatrixType;
82 typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar;
83 const RealScalar
b[] = {30240.L, 15120.L, 3360.L, 420.L, 30.L, 1.L};
84 const MatrixType A2 = A * A;
85 const MatrixType A4 = A2 * A2;
86 const MatrixType tmp =
b[5] * A4 +
b[3] * A2 +
b[1] * MatrixType::Identity(A.rows(), A.cols());
87 U.noalias() = A * tmp;
88 V =
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(A.rows(), A.cols());
96template <
typename MatA,
typename MatU,
typename MatV>
98 typedef typename MatA::PlainObject MatrixType;
99 typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar;
100 const RealScalar
b[] = {17297280.L, 8648640.L, 1995840.L, 277200.L, 25200.L, 1512.L, 56.L, 1.L};
101 const MatrixType A2 = A * A;
102 const MatrixType A4 = A2 * A2;
103 const MatrixType A6 = A4 * A2;
104 const MatrixType tmp =
b[7] * A6 +
b[5] * A4 +
b[3] * A2 +
b[1] * MatrixType::Identity(A.rows(), A.cols());
105 U.noalias() = A * tmp;
106 V =
b[6] * A6 +
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(A.rows(), A.cols());
114template <
typename MatA,
typename MatU,
typename MatV>
116 typedef typename MatA::PlainObject MatrixType;
117 typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar;
118 const RealScalar
b[] = {17643225600.L, 8821612800.L, 2075673600.L, 302702400.L, 30270240.L,
119 2162160.L, 110880.L, 3960.L, 90.L, 1.L};
120 const MatrixType A2 = A * A;
121 const MatrixType A4 = A2 * A2;
122 const MatrixType A6 = A4 * A2;
123 const MatrixType A8 = A6 * A2;
124 const MatrixType tmp =
125 b[9] * A8 +
b[7] * A6 +
b[5] * A4 +
b[3] * A2 +
b[1] * MatrixType::Identity(A.rows(), A.cols());
126 U.noalias() = A * tmp;
127 V =
b[8] * A8 +
b[6] * A6 +
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(A.rows(), A.cols());
135template <
typename MatA,
typename MatU,
typename MatV>
137 typedef typename MatA::PlainObject MatrixType;
138 typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar;
139 const RealScalar
b[] = {64764752532480000.L,
153 const MatrixType A2 = A * A;
154 const MatrixType A4 = A2 * A2;
155 const MatrixType A6 = A4 * A2;
156 V =
b[13] * A6 +
b[11] * A4 +
b[9] * A2;
157 MatrixType tmp = A6 * V;
158 tmp +=
b[7] * A6 +
b[5] * A4 +
b[3] * A2 +
b[1] * MatrixType::Identity(A.rows(), A.cols());
159 U.noalias() = A * tmp;
160 tmp =
b[12] * A6 +
b[10] * A4 +
b[8] * A2;
161 V.noalias() = A6 * tmp;
162 V +=
b[6] * A6 +
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(A.rows(), A.cols());
172#if LDBL_MANT_DIG > 64
173template <
typename MatA,
typename MatU,
typename MatV>
174void matrix_exp_pade17(
const MatA& A, MatU& U, MatV& V) {
175 typedef typename MatA::PlainObject MatrixType;
176 typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar;
177 const RealScalar
b[] = {830034394580628357120000.L,
178 415017197290314178560000.L,
179 100610229646136770560000.L,
180 15720348382208870400000.L,
181 1774878043152614400000.L,
182 153822763739893248000.L,
183 10608466464820224000.L,
184 595373117923584000.L,
195 const MatrixType A2 = A * A;
196 const MatrixType A4 = A2 * A2;
197 const MatrixType A6 = A4 * A2;
198 const MatrixType A8 = A4 * A4;
199 V =
b[17] * A8 +
b[15] * A6 +
b[13] * A4 +
b[11] * A2;
200 MatrixType tmp = A8 * V;
201 tmp +=
b[9] * A8 +
b[7] * A6 +
b[5] * A4 +
b[3] * A2 +
b[1] * MatrixType::Identity(A.rows(), A.cols());
202 U.noalias() = A * tmp;
203 tmp =
b[16] * A8 +
b[14] * A6 +
b[12] * A4 +
b[10] * A2;
204 V.noalias() = tmp * A8;
205 V +=
b[8] * A8 +
b[6] * A6 +
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(A.rows(), A.cols());
209template <typename MatrixType, typename RealScalar = typename NumTraits<typename traits<MatrixType>::Scalar>::Real>
218 static void run(
const MatrixType&
arg, MatrixType& U, MatrixType& V,
int& squarings);
221template <
typename MatrixType>
223 template <
typename ArgType>
224 static void run(
const ArgType&
arg, MatrixType& U, MatrixType& V,
int& squarings) {
227 const float l1norm =
arg.cwiseAbs().colwise().sum().maxCoeff();
229 if (l1norm < 4.258730016922831e-001f) {
231 }
else if (l1norm < 1.880152677804762e+000f) {
234 const float maxnorm = 3.925724783138660f;
235 frexp(l1norm / maxnorm, &squarings);
236 if (squarings < 0) squarings = 0;
243template <
typename MatrixType>
245 typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real
RealScalar;
246 template <
typename ArgType>
247 static void run(
const ArgType&
arg, MatrixType& U, MatrixType& V,
int& squarings) {
250 const RealScalar l1norm =
arg.cwiseAbs().colwise().sum().maxCoeff();
252 if (l1norm < 1.495585217958292e-002) {
254 }
else if (l1norm < 2.539398330063230e-001) {
256 }
else if (l1norm < 9.504178996162932e-001) {
258 }
else if (l1norm < 2.097847961257068e+000) {
262 frexp(l1norm / maxnorm, &squarings);
263 if (squarings < 0) squarings = 0;
270template <
typename MatrixType>
272 template <
typename ArgType>
273 static void run(
const ArgType&
arg, MatrixType& U, MatrixType& V,
int& squarings) {
274#if LDBL_MANT_DIG == 53
281 const long double l1norm =
arg.cwiseAbs().colwise().sum().maxCoeff();
284#if LDBL_MANT_DIG <= 64
286 if (l1norm < 4.1968497232266989671e-003L) {
288 }
else if (l1norm < 1.1848116734693823091e-001L) {
290 }
else if (l1norm < 5.5170388480686700274e-001L) {
292 }
else if (l1norm < 1.3759868875587845383e+000L) {
295 const long double maxnorm = 4.0246098906697353063L;
296 frexp(l1norm / maxnorm, &squarings);
297 if (squarings < 0) squarings = 0;
302#elif LDBL_MANT_DIG <= 106
304 if (l1norm < 3.2787892205607026992947488108213e-005L) {
306 }
else if (l1norm < 6.4467025060072760084130906076332e-003L) {
308 }
else if (l1norm < 6.8988028496595374751374122881143e-002L) {
310 }
else if (l1norm < 2.7339737518502231741495857201670e-001L) {
312 }
else if (l1norm < 1.3203382096514474905666448850278e+000L) {
315 const long double maxnorm = 3.2579440895405400856599663723517L;
316 frexp(l1norm / maxnorm, &squarings);
317 if (squarings < 0) squarings = 0;
319 matrix_exp_pade17(A, U, V);
322#elif LDBL_MANT_DIG <= 113
324 if (l1norm < 1.639394610288918690547467954466970e-005L) {
326 }
else if (l1norm < 4.253237712165275566025884344433009e-003L) {
328 }
else if (l1norm < 5.125804063165764409885122032933142e-002L) {
330 }
else if (l1norm < 2.170000765161155195453205651889853e-001L) {
332 }
else if (l1norm < 1.125358383453143065081397882891878e+000L) {
335 const long double maxnorm = 2.884233277829519311757165057717815L;
336 frexp(l1norm / maxnorm, &squarings);
337 if (squarings < 0) squarings = 0;
339 matrix_exp_pade17(A, U, V);
345 eigen_assert(
false &&
"Bug in MatrixExponential");
358#if LDBL_MANT_DIG <= 113
363template <
typename ArgType,
typename ResultType>
366 typedef typename ArgType::PlainObject MatrixType;
370 MatrixType numer = U + V;
371 MatrixType denom = -U + V;
372 result = denom.partialPivLu().solve(numer);
373 for (
int i = 0; i < squarings; i++) result *= result;
381template <
typename ArgType,
typename ResultType>
384 typedef typename ArgType::PlainObject MatrixType;
385 typedef typename traits<MatrixType>::Scalar Scalar;
386 typedef typename NumTraits<Scalar>::Real RealScalar;
387 typedef typename std::complex<RealScalar> ComplexScalar;
388 result =
arg.matrixFunction(internal::stem_function_exp<ComplexScalar>);
403template <
typename Derived>
416 template <
typename ResultType>
417 inline void evalTo(ResultType& result)
const {
430template <
typename Derived>
436template <
typename Derived>
438 eigen_assert(rows() == cols());
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
\rst Returns a named argument to be used in a formatting function.
Definition: core.h:1841
dimensionless::scalar_t exp(const ScalarUnit x) noexcept
Compute exponential function.
Definition: math.h:332
void matrix_exp_pade7(const MatA &A, MatU &U, MatV &V)
Compute the (7,7)-Padé approximant to the exponential.
Definition: MatrixExponential.h:97
void matrix_exp_pade9(const MatA &A, MatU &U, MatV &V)
Compute the (9,9)-Padé approximant to the exponential.
Definition: MatrixExponential.h:115
void matrix_exp_compute(const ArgType &arg, ResultType &result, true_type)
Definition: MatrixExponential.h:364
void matrix_exp_pade3(const MatA &A, MatU &U, MatV &V)
Compute the (3,3)-Padé approximant to the exponential.
Definition: MatrixExponential.h:64
void matrix_exp_pade13(const MatA &A, MatU &U, MatV &V)
Compute the (13,13)-Padé approximant to the exponential.
Definition: MatrixExponential.h:136
void matrix_exp_pade5(const MatA &A, MatU &U, MatV &V)
Compute the (5,5)-Padé approximant to the exponential.
Definition: MatrixExponential.h:80
Definition: MatrixSquareRoot.h:16
type
Definition: core.h:556
auto pow(const UnitType &value) noexcept -> unit_t< typename units::detail::power_of_unit< power, typename units::traits::unit_t_traits< UnitType >::unit_type >::type, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the value of value raised to the power
Definition: base.h:2806
Proxy for the matrix exponential of some matrix (expression).
Definition: MatrixExponential.h:404
void evalTo(ResultType &result) const
Compute the matrix exponential.
Definition: MatrixExponential.h:417
MatrixExponentialReturnValue(const Derived &src)
Constructor.
Definition: MatrixExponential.h:410
Index rows() const
Definition: MatrixExponential.h:422
const internal::ref_selector< Derived >::type m_src
Definition: MatrixExponential.h:426
Index cols() const
Definition: MatrixExponential.h:423
Scaling operator.
Definition: MatrixExponential.h:27
const ComplexScalar operator()(const ComplexScalar &x) const
Scale a matrix coefficient.
Definition: MatrixExponential.h:49
std::complex< RealScalar > ComplexScalar
Definition: MatrixExponential.h:43
const RealScalar operator()(const RealScalar &x) const
Scale a matrix coefficient.
Definition: MatrixExponential.h:38
MatrixExponentialScalingOp(int squarings)
Constructor.
Definition: MatrixExponential.h:32
Definition: MatrixExponential.h:353
static void run(const ArgType &arg, MatrixType &U, MatrixType &V, int &squarings)
Definition: MatrixExponential.h:247
NumTraits< typenametraits< MatrixType >::Scalar >::Real RealScalar
Definition: MatrixExponential.h:245
static void run(const ArgType &arg, MatrixType &U, MatrixType &V, int &squarings)
Definition: MatrixExponential.h:224
static void run(const ArgType &arg, MatrixType &U, MatrixType &V, int &squarings)
Definition: MatrixExponential.h:273
Compute the (17,17)-Padé approximant to the exponential.
Definition: MatrixExponential.h:210
static void run(const MatrixType &arg, MatrixType &U, MatrixType &V, int &squarings)
Compute Padé approximant to the exponential.
Derived::PlainObject ReturnType
Definition: MatrixExponential.h:432