Eigen-Contrib  5.0.1
 
Loading...
Searching...
No Matches
Eigen::MatrixPower< MatrixType > Class Template Reference

#include <contrib/Eigen/src/MatrixFunctions/MatrixPower.h>

Detailed Description

template<typename MatrixType>
class Eigen::MatrixPower< MatrixType >

Class for computing matrix powers.

Template Parameters
MatrixTypetype of the base, expected to be an instantiation of the Matrix class template.

This class is capable of computing real/complex matrices raised to an arbitrary real power. Meanwhile, it saves the result of Schur decomposition if a non-integral power has ever been calculated. Therefore, if you want to compute multiple (>= 2) matrix powers for the same matrix, using the class directly is more efficient than calling MatrixBase::pow().

Example:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
#include <contrib/Eigen/MatrixFunctions>
#include <iostream>
using namespace Eigen;
int main() {
Matrix4cd A = Matrix4cd::Random();
MatrixPower<Matrix4cd> Apow(A);
std::cout << "The matrix A is:\n"
<< A
<< "\n\n"
"A^3.1 is:\n"
<< Apow(3.1)
<< "\n\n"
"A^3.3 is:\n"
<< Apow(3.3)
<< "\n\n"
"A^3.7 is:\n"
<< Apow(3.7)
<< "\n\n"
"A^3.9 is:\n"
<< Apow(3.9) << std::endl;
return 0;
}
Matrix< std::complex< double >, 4, 4 > Matrix4cd
Namespace containing all symbols from the Eigen library.

Output:

The matrix A is:
 (-0.211234,0.596881)   (0.434594,0.213937) (-0.407936,0.0485741)  (0.898654,-0.827888)
 (-0.604897,0.536459)  (-0.514227,0.608353)    (0.94555,0.542715)  (0.326453,-0.302214)
   (0.10794,0.257741) (-0.198111,-0.782383)   (0.539828,0.783059) (-0.959954,-0.873808)
 (0.0268015,0.832391)  (-0.563486,0.678224)  (-0.295084,0.838054)    (0.941268,0.70184)

A^3.1 is:
  (-1.93513,0.648575)  (-2.07718,-0.703256)    (-3.87582,3.83458)     (2.86313,2.40978)
  (0.568806,0.785524)    (2.19191,0.535855) (-0.709163,-0.486426)     (1.1808,-2.02005)
    (1.16555,2.13452)    (0.413611,2.48565)     (5.47544,2.85412)     (1.9366,-4.81275)
  (-1.56915,0.251293)    (-2.00077,1.72421)   (-4.49146,-0.84688)      (2.4147,6.60277)

A^3.3 is:
   (-2.14002,0.225285)    (-1.43881,-1.15283)     (-5.37706,3.39506)      (3.28526,2.78026)
    (0.416205,1.00085)       (2.2285,1.39662) (-0.0914379,-0.720032)      (1.9675,-2.10796)
    (0.790046,2.34299)     (-0.183361,2.1086)       (5.6589,4.53725)     (2.46589,-5.37454)
    (-2.2067,0.313465)     (-2.90677,1.72209)    (-5.11023,-1.00965)      (2.23473,7.84969)

A^3.7 is:
(-1.97863,-0.413093) (0.284849,-0.700203)   (-7.82754,1.30184)    (4.49337,4.09104)
 (0.0579547,1.35991)    (1.31385,3.18425)   (1.58929,-0.18202)   (3.62347,-1.55686)
  (0.333883,2.26581) (-0.307753,0.597838)    (4.75734,7.98149)   (3.86857,-6.87044)
 (-3.8398,-0.361606)  (-4.82091,0.916708)  (-7.13948,-1.67237)    (1.52857,11.0221)

A^3.9 is:
 (-1.77174,-0.404906)     (0.911227,0.3358) (-8.51159,-0.0843889)     (5.22304,5.15299)
  (-0.161506,1.53969)     (0.332862,3.8326)     (2.3709,0.761741)   (4.31279,-0.958972)
   (0.439061,2.15025)  (0.398939,-0.183662)     (3.78526,9.45362)    (4.85176,-7.86587)
  (-4.61349,-1.14578)   (-5.66312,0.165718)   (-8.56205,-2.39729)    (0.865657,13.0295)

Public Member Functions

template<typename ResultType>
void compute (ResultType &res, RealScalar p)
 Compute the matrix power.
 
 MatrixPower (const MatrixType &A)
 Constructor.
 
const MatrixPowerParenthesesReturnValue< MatrixType > operator() (RealScalar p)
 Returns the matrix power.
 

Constructor & Destructor Documentation

◆ MatrixPower()

template<typename MatrixType>
Eigen::MatrixPower< MatrixType >::MatrixPower ( const MatrixType & A)
inlineexplicit

Constructor.

Parameters
[in]Athe base of the matrix power.

The class stores a reference to A, so it should not be changed (or destroyed) before evaluation.

Member Function Documentation

◆ compute()

template<typename MatrixType>
template<typename ResultType>
void Eigen::MatrixPower< MatrixType >::compute ( ResultType & res,
RealScalar p )

Compute the matrix power.

Parameters
[in]pexponent, a real scalar.
[out]res\( A^p \) where A is specified in the constructor.

◆ operator()()

template<typename MatrixType>
const MatrixPowerParenthesesReturnValue< MatrixType > Eigen::MatrixPower< MatrixType >::operator() ( RealScalar p)
inline

Returns the matrix power.

Parameters
[in]pexponent, a real scalar.
Returns
The expression \( A^p \), where A is specified in the constructor.

The documentation for this class was generated from the following file: