Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
 Eigen  3.4.99 (git rev 10c77b0ff44d0b9cb0b252cfa0ccaaa39d3c5da4)
Eigen::HessenbergDecomposition< _MatrixType > Class Template Reference

## Detailed Description

### template<typename _MatrixType> class Eigen::HessenbergDecomposition< _MatrixType >

Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation.

This is defined in the Eigenvalues module.

#include <Eigen/Eigenvalues>
Template Parameters
 _MatrixType the type of the matrix of which we are computing the Hessenberg decomposition

This class performs an Hessenberg decomposition of a matrix $$A$$. In the real case, the Hessenberg decomposition consists of an orthogonal matrix $$Q$$ and a Hessenberg matrix $$H$$ such that $$A = Q H Q^T$$. An orthogonal matrix is a matrix whose inverse equals its transpose ( $$Q^{-1} = Q^T$$). A Hessenberg matrix has zeros below the subdiagonal, so it is almost upper triangular. The Hessenberg decomposition of a complex matrix is $$A = Q H Q^*$$ with $$Q$$ unitary (that is, $$Q^{-1} = Q^*$$).

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.

class ComplexSchur, class Tridiagonalization, QR Module

## Public Types

typedef Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
Type for vector of Householder coefficients. More...

typedef HouseholderSequence< MatrixType, typename internal::remove_all< typename CoeffVectorType::ConjugateReturnType >::type > HouseholderSequenceType
Return type of matrixQ()

typedef Eigen::Index Index

typedef _MatrixType MatrixType
Synonym for the template parameter _MatrixType.

typedef MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.

## Public Member Functions

template<typename InputType >
HessenbergDecompositioncompute (const EigenBase< InputType > &matrix)
Computes Hessenberg decomposition of given matrix. More...

template<typename InputType >
HessenbergDecomposition (const EigenBase< InputType > &matrix)
Constructor; computes Hessenberg decomposition of given matrix. More...

HessenbergDecomposition (Index size=Size==Dynamic ? 2 :Size)
Default constructor; the decomposition will be computed later. More...

const CoeffVectorTypehouseholderCoefficients () const
Returns the Householder coefficients. More...

MatrixHReturnType matrixH () const
Constructs the Hessenberg matrix H in the decomposition. More...

HouseholderSequenceType matrixQ () const
Reconstructs the orthogonal matrix Q in the decomposition. More...

const MatrixTypepackedMatrix () const
Returns the internal representation of the decomposition. More...

## ◆ CoeffVectorType

template<typename _MatrixType >
 typedef Matrix 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.

## ◆ Index

template<typename _MatrixType >
 typedef Eigen::Index Eigen::HessenbergDecomposition< _MatrixType >::Index
Deprecated:
since Eigen 3.3

## ◆ HessenbergDecomposition() [1/2]

template<typename _MatrixType >
 Eigen::HessenbergDecomposition< _MatrixType >::HessenbergDecomposition ( Index size = Size==Dynamic ? 2 : Size )
inlineexplicit

Default constructor; the decomposition will be computed later.

Parameters
 [in] size 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.

compute() for an example.

## ◆ HessenbergDecomposition() [2/2]

template<typename _MatrixType >
template<typename InputType >
 Eigen::HessenbergDecomposition< _MatrixType >::HessenbergDecomposition ( const EigenBase< InputType > & matrix )
inlineexplicit

Constructor; computes Hessenberg decomposition of given matrix.

Parameters
 [in] matrix Square matrix whose Hessenberg decomposition is to be computed.

This constructor calls compute() to compute the Hessenberg decomposition.

matrixH() for an example.

## ◆ compute()

template<typename _MatrixType >
template<typename InputType >
 HessenbergDecomposition& Eigen::HessenbergDecomposition< _MatrixType >::compute ( const EigenBase< InputType > & matrix )
inline

Computes Hessenberg decomposition of given matrix.

Parameters
 [in] matrix 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 $$10n^3/3$$ flops, where $$n$$ 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;
static const RandomReturnType Random()
Definition: Random.h:113

Output:

The matrix H in the decomposition of A is:
(-1,-0.737)  (0.744,-0.288) (-0.00724,1.29) (0.371,-0.0914)
(-1.24,0)   (0.849,0.262) (-0.883,-0.943)   (-1.16,0.229)
(0,0)       (0.684,0)  (-0.46,-0.211)  (0.474,-0.359)
(0,0)           (0,0)       (0.272,0)  (0.0332,0.886)
The matrix H in the decomposition of 2A is:
(-2,-1.47)  (1.49,-0.575) (-0.0145,2.59) (0.741,-0.183)
(-2.48,0)    (1.7,0.524)  (-1.77,-1.89)  (-2.33,0.458)
(0,0)       (1.37,0) (-0.92,-0.422) (0.948,-0.719)
(0,0)          (0,0)      (0.543,0)  (0.0665,1.77)


## ◆ householderCoefficients()

template<typename _MatrixType >
 const CoeffVectorType& Eigen::HessenbergDecomposition< _MatrixType >::householderCoefficients ( ) const
inline

Returns the Householder coefficients.

Returns
a const reference to the vector of Householder coefficients
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

The Householder coefficients allow the reconstruction of the matrix $$Q$$ in the Hessenberg decomposition from the packed data.

packedMatrix(), Householder module

## ◆ matrixH()

template<typename _MatrixType >
 MatrixHReturnType Eigen::HessenbergDecomposition< _MatrixType >::matrixH ( ) const
inline

Constructs the Hessenberg matrix H in the decomposition.

Returns
expression object representing the matrix H
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

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:
-1  0.0655   0.359   0.662
-0.737  -0.562   0.869  -0.931
0.511  -0.906  -0.233  -0.893
-0.0827   0.358  0.0388  0.0594
The Hessenberg matrix H is:
-1  0.0891  -0.143   0.737
0.901  -0.432   0.775 0.00631
0    -1.2 -0.0754     1.2
0       0  -0.133  -0.228
The orthogonal matrix Q is:
1       0       0       0
0  -0.818   -0.57  0.0776
0   0.568  -0.779   0.267
0 -0.0918   0.263   0.961
Q H Q^T is:
-1  0.0655   0.359   0.662
-0.737  -0.562   0.869  -0.931
0.511  -0.906  -0.233  -0.893
-0.0827   0.358  0.0388  0.0594

matrixQ(), packedMatrix()

## ◆ matrixQ()

template<typename _MatrixType >
 HouseholderSequenceType Eigen::HessenbergDecomposition< _MatrixType >::matrixQ ( ) const
inline

Reconstructs the orthogonal matrix Q in the decomposition.

Returns
object representing the matrix Q
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

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.

matrixH() for an example, class HouseholderSequence

## ◆ packedMatrix()

template<typename _MatrixType >
 const MatrixType& Eigen::HessenbergDecomposition< _MatrixType >::packedMatrix ( ) const
inline

Returns the internal representation of the decomposition.

Returns
a const reference to a matrix with the internal representation of the decomposition.
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

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 $$Q = H_{N-1} \ldots H_1 H_0$$. Here, the matrices $$H_i$$ are the Householder transformations $$H_i = (I - h_i v_i v_i^T)$$ where $$h_i$$ is the $$i$$th Householder coefficient and $$v_i$$ is the Householder vector defined by $$v_i = [ 0, \ldots, 0, 1, M(i+2,i), \ldots, M(N-1,i) ]^T$$ 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:
-1  0.0655   0.359   0.662
-0.737  -0.562   0.869  -0.931
0.511  -0.906  -0.233  -0.893
-0.0827   0.358  0.0388  0.0594
The packed matrix M is:
-1  0.0891  -0.143   0.737
0.901  -0.432   0.775 0.00631
-0.312    -1.2 -0.0754     1.2
0.0505  -0.149  -0.133  -0.228
The upper Hessenberg part corresponds to the matrix H, which is:
-1  0.0891  -0.143   0.737
0.901  -0.432   0.775 0.00631
0    -1.2 -0.0754     1.2
0       0  -0.133  -0.228
The vector of Householder coefficients is:
1.82
1.96
0