template<typename _MatrixType>
HessenbergDecomposition class
Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation.
Template parameters | |
---|---|
_MatrixType | the type of the matrix of which we are computing the Hessenberg decomposition |
Contents
This is defined in the Eigenvalues module. #include <Eigen/Eigenvalues>
This class performs an Hessenberg decomposition of a matrix . In the real case, the Hessenberg decomposition consists of an orthogonal matrix and a Hessenberg matrix such that . An orthogonal matrix is a matrix whose inverse equals its transpose ( ). A Hessenberg matrix has zeros below the subdiagonal, so it is almost upper triangular. The Hessenberg decomposition of a complex matrix is with unitary (that is, ).
Call the function compute() to compute the Hessenberg decomposition of a given matrix. Alternatively, you can use the HessenbergDecomposition(const MatrixType&) constructor which computes the Hessenberg decomposition at construction time. Once the decomposition is computed, you can use the matrixH() and matrixQ() functions to construct the matrices H and Q in the decomposition.
The documentation for matrixH() contains an example of the typical use of this class.
Public types
- using CoeffVectorType = Matrix<Scalar, SizeMinusOne, 1, Options&~RowMajor, MaxSizeMinusOne, 1>
- Type for vector of Householder coefficients.
- using HouseholderSequenceType = HouseholderSequence<MatrixType, typename internal::remove_all<typename CoeffVectorType::ConjugateReturnType>::type>
- Return type of matrixQ()
-
using Index = Eigen::
Index deprecated - using MatrixType = _MatrixType
- Synonym for the template parameter
_MatrixType
. - using Scalar = MatrixType::Scalar
- Scalar type for matrices of type MatrixType.
Constructors, destructors, conversion operators
- HessenbergDecomposition(Index size = Size==Dynamic ? 2 :Size) explicit
- Default constructor; the decomposition will be computed later.
-
template<typename InputType>HessenbergDecomposition(const EigenBase<InputType>& matrix) explicit
- Constructor; computes Hessenberg decomposition of given matrix.
Public functions
-
template<typename InputType>auto compute(const EigenBase<InputType>& matrix) -> HessenbergDecomposition&
- Computes Hessenberg decomposition of given matrix.
- auto householderCoefficients() const -> const CoeffVectorType&
- Returns the Householder coefficients.
- auto matrixH() const -> MatrixHReturnType
- Constructs the Hessenberg matrix H in the decomposition.
- auto matrixQ() const -> HouseholderSequenceType
- Reconstructs the orthogonal matrix Q in the decomposition.
- auto packedMatrix() const -> const MatrixType&
- Returns the internal representation of the decomposition.
Typedef documentation
template<typename _MatrixType>
typedef Matrix<Scalar, SizeMinusOne, 1, Options&~RowMajor, MaxSizeMinusOne, 1> Eigen:: HessenbergDecomposition<_MatrixType>:: CoeffVectorType
Type for vector of Householder coefficients.
This is column vector with entries of type Scalar. The length of the vector is one less than the size of MatrixType, if it is a fixed-side type.
template<typename _MatrixType>
typedef Eigen:: Index Eigen:: HessenbergDecomposition<_MatrixType>:: Index
Function documentation
template<typename _MatrixType>
Eigen:: HessenbergDecomposition<_MatrixType>:: HessenbergDecomposition(Index size = Size==Dynamic ? 2 :Size) explicit
Default constructor; the decomposition will be computed later.
Parameters | |
---|---|
size in | The size of the matrix whose Hessenberg decomposition will be computed. |
The default constructor is useful in cases in which the user intends to perform decompositions via compute(). The size
parameter is only used as a hint. It is not an error to give a wrong size
, but it may impair performance.
template<typename _MatrixType>
template<typename InputType>
Eigen:: HessenbergDecomposition<_MatrixType>:: HessenbergDecomposition(const EigenBase<InputType>& matrix) explicit
Constructor; computes Hessenberg decomposition of given matrix.
Parameters | |
---|---|
matrix in | Square matrix whose Hessenberg decomposition is to be computed. |
This constructor calls compute() to compute the Hessenberg decomposition.
template<typename _MatrixType>
template<typename InputType>
HessenbergDecomposition& Eigen:: HessenbergDecomposition<_MatrixType>:: compute(const EigenBase<InputType>& matrix)
Computes Hessenberg decomposition of given matrix.
Parameters | |
---|---|
matrix in | Square matrix whose Hessenberg decomposition is to be computed. |
Returns | Reference to *this |
The Hessenberg decomposition is computed by bringing the columns of the matrix successively in the required form using Householder reflections (see, e.g., Algorithm 7.4.2 in Golub & Van Loan, Matrix Computations). The cost is flops, where denotes the size of the given matrix.
This method reuses of the allocated data in the HessenbergDecomposition object.
Example:
MatrixXcf A = MatrixXcf::Random(4,4); HessenbergDecomposition<MatrixXcf> hd(4); hd.compute(A); cout << "The matrix H in the decomposition of A is:" << endl << hd.matrixH() << endl; hd.compute(2*A); // re-use hd to compute and store decomposition of 2A cout << "The matrix H in the decomposition of 2A is:" << endl << hd.matrixH() << endl;
Output:
The matrix H in the decomposition of A is: (-0.211,0.68) (0.346,0.216) (-0.688,0.00979) (0.0451,0.584) (-1.45,0) (-0.0574,-0.0123) (-0.196,0.385) (0.395,0.389) (0,0) (1.68,0) (-0.397,-0.552) (0.156,-0.241) (0,0) (0,0) (1.56,0) (0.876,-0.423) The matrix H in the decomposition of 2A is: (-0.422,1.36) (0.691,0.431) (-1.38,0.0196) (0.0902,1.17) (-2.91,0) (-0.115,-0.0246) (-0.392,0.77) (0.791,0.777) (0,0) (3.36,0) (-0.795,-1.1) (0.311,-0.482) (0,0) (0,0) (3.12,0) (1.75,-0.846)
template<typename _MatrixType>
const CoeffVectorType& Eigen:: HessenbergDecomposition<_MatrixType>:: householderCoefficients() const
Returns the Householder coefficients.
Returns | a const reference to the vector of Householder coefficients |
---|
The Householder coefficients allow the reconstruction of the matrix in the Hessenberg decomposition from the packed data.
template<typename _MatrixType>
MatrixHReturnType Eigen:: HessenbergDecomposition<_MatrixType>:: matrixH() const
Constructs the Hessenberg matrix H in the decomposition.
Returns | expression object representing the matrix H |
---|
The object returned by this function constructs the Hessenberg matrix H when it is assigned to a matrix or otherwise evaluated. The matrix H is constructed from the packed matrix as returned by packedMatrix(): The upper part (including the subdiagonal) of the packed matrix contains the matrix H. It may sometimes be better to directly use the packed matrix instead of constructing the matrix H.
Example:
Matrix4f A = MatrixXf::Random(4,4); cout << "Here is a random 4x4 matrix:" << endl << A << endl; HessenbergDecomposition<MatrixXf> hessOfA(A); MatrixXf H = hessOfA.matrixH(); cout << "The Hessenberg matrix H is:" << endl << H << endl; MatrixXf Q = hessOfA.matrixQ(); cout << "The orthogonal matrix Q is:" << endl << Q << endl; cout << "Q H Q^T is:" << endl << Q * H * Q.transpose() << endl;
Output:
Here is a random 4x4 matrix: 0.68 0.823 -0.444 -0.27 -0.211 -0.605 0.108 0.0268 0.566 -0.33 -0.0452 0.904 0.597 0.536 0.258 0.832 The Hessenberg matrix H is: 0.68 -0.691 -0.645 0.235 0.849 0.836 -0.419 0.794 0 -0.469 -0.547 -0.0731 0 0 -0.559 -0.107 The orthogonal matrix Q is: 1 0 0 0 0 -0.249 -0.958 0.144 0 0.667 -0.277 -0.692 0 0.703 -0.0761 0.707 Q H Q^T is: 0.68 0.823 -0.444 -0.27 -0.211 -0.605 0.108 0.0268 0.566 -0.33 -0.0452 0.904 0.597 0.536 0.258 0.832
template<typename _MatrixType>
HouseholderSequenceType Eigen:: HessenbergDecomposition<_MatrixType>:: matrixQ() const
Reconstructs the orthogonal matrix Q in the decomposition.
Returns | object representing the matrix Q |
---|
This function returns a light-weight object of template class HouseholderSequence. You can either apply it directly to a matrix or you can convert it to a matrix of type MatrixType.
template<typename _MatrixType>
const MatrixType& Eigen:: HessenbergDecomposition<_MatrixType>:: packedMatrix() const
Returns the internal representation of the decomposition.
Returns | a const reference to a matrix with the internal representation of the decomposition. |
---|
The returned matrix contains the following information:
- the upper part and lower sub-diagonal represent the Hessenberg matrix H
- the rest of the lower part contains the Householder vectors that, combined with Householder coefficients returned by householderCoefficients(), allows to reconstruct the matrix Q as . Here, the matrices are the Householder transformations where is the th Householder coefficient and is the Householder vector defined by with M the matrix returned by this function.
See LAPACK for further details on this packed storage.
Example:
Matrix4d A = Matrix4d::Random(4,4); cout << "Here is a random 4x4 matrix:" << endl << A << endl; HessenbergDecomposition<Matrix4d> hessOfA(A); Matrix4d pm = hessOfA.packedMatrix(); cout << "The packed matrix M is:" << endl << pm << endl; cout << "The upper Hessenberg part corresponds to the matrix H, which is:" << endl << hessOfA.matrixH() << endl; Vector3d hc = hessOfA.householderCoefficients(); cout << "The vector of Householder coefficients is:" << endl << hc << endl;
Output:
Here is a random 4x4 matrix: 0.68 0.823 -0.444 -0.27 -0.211 -0.605 0.108 0.0268 0.566 -0.33 -0.0452 0.904 0.597 0.536 0.258 0.832 The packed matrix M is: 0.68 -0.691 -0.645 0.235 0.849 0.836 -0.419 0.794 -0.534 -0.469 -0.547 -0.0731 -0.563 0.344 -0.559 -0.107 The upper Hessenberg part corresponds to the matrix H, which is: 0.68 -0.691 -0.645 0.235 0.849 0.836 -0.419 0.794 0 -0.469 -0.547 -0.0731 0 0 -0.559 -0.107 The vector of Householder coefficients is: 1.25 1.79 0