Eigen  5.0.1
 
Loading...
Searching...
No Matches
Eigen::Tridiagonalization< MatrixType_ > Class Template Reference

#include <Eigen/src/Eigenvalues/Tridiagonalization.h>

Detailed Description

template<typename MatrixType_>
class Eigen::Tridiagonalization< MatrixType_ >

Tridiagonal decomposition of a selfadjoint matrix.

This is defined in the Eigenvalues module.

#include <Eigen/Eigenvalues>
Template Parameters
MatrixType_the type of the matrix of which we are computing the tridiagonal decomposition; this is expected to be an instantiation of the Matrix class template.

This class performs a tridiagonal decomposition of a selfadjoint matrix \( A \) such that: \( A = Q T Q^* \) where \( Q \) is unitary and \( T \) a real symmetric tridiagonal matrix.

A tridiagonal matrix is a matrix which has nonzero elements only on the main diagonal and the first diagonal below and above it. The Hessenberg decomposition of a selfadjoint matrix is in fact a tridiagonal decomposition. This class is used in SelfAdjointEigenSolver to compute the eigenvalues and eigenvectors of a selfadjoint matrix.

Call the function compute() to compute the tridiagonal decomposition of a given matrix. Alternatively, you can use the Tridiagonalization(const MatrixType&) constructor which computes the tridiagonal Schur decomposition at construction time. Once the decomposition is computed, you can use the matrixQ() and matrixT() functions to retrieve the matrices Q and T in the decomposition.

The documentation of Tridiagonalization(const MatrixType&) contains an example of the typical use of this class.

See also
class HessenbergDecomposition, class SelfAdjointEigenSolver

Public Types

using HouseholderSequenceType
 Return type of matrixQ()
 
using Index
 
using MatrixType
 Synonym for the template parameter MatrixType_.
 

Public Member Functions

template<typename InputType>
Tridiagonalization & compute (const EigenBase< InputType > &matrix)
 Computes tridiagonal decomposition of given matrix.
 
DiagonalReturnType diagonal () const
 Returns the diagonal of the tridiagonal matrix T in the decomposition.
 
CoeffVectorType householderCoefficients () const
 Returns the Householder coefficients.
 
HouseholderSequenceType matrixQ () const
 Returns the unitary matrix Q in the decomposition.
 
MatrixTReturnType matrixT () const
 Returns an expression of the tridiagonal matrix T in the decomposition.
 
const MatrixType & packedMatrix () const
 Returns the internal representation of the decomposition.
 
SubDiagonalReturnType subDiagonal () const
 Returns the subdiagonal of the tridiagonal matrix T in the decomposition.
 
template<typename InputType>
 Tridiagonalization (const EigenBase< InputType > &matrix)
 Constructor; computes tridiagonal decomposition of given matrix.
 
template<typename InputType>
 Tridiagonalization (EigenBase< InputType > &matrix)
 Constructor for inplace decomposition .
 
 Tridiagonalization (Index size=Size==Dynamic ? 2 :Size)
 Default constructor.
 

Member Typedef Documentation

◆ Index

template<typename MatrixType_>
using Eigen::Tridiagonalization< MatrixType_ >::Index

Constructor & Destructor Documentation

◆ Tridiagonalization() [1/3]

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

Default constructor.

Parameters
[in]sizePositive integer, size of the matrix whose tridiagonal 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.

See also
compute() for an example.

◆ Tridiagonalization() [2/3]

template<typename MatrixType_>
template<typename InputType>
Eigen::Tridiagonalization< MatrixType_ >::Tridiagonalization ( const EigenBase< InputType > & matrix)
inlineexplicit

Constructor; computes tridiagonal decomposition of given matrix.

Parameters
[in]matrixSelfadjoint matrix whose tridiagonal decomposition is to be computed.

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

Example:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
MatrixXd X = MatrixXd::Random(5, 5);
MatrixXd A = X + X.transpose();
cout << "Here is a random symmetric 5x5 matrix:" << endl << A << endl << endl;
MatrixXd Q = triOfA.matrixQ();
cout << "The orthogonal matrix Q is:" << endl << Q << endl;
MatrixXd T = triOfA.matrixT();
cout << "The tridiagonal matrix T is:" << endl << T << endl << endl;
cout << "Q * T * Q^T = " << endl << Q * T * Q.transpose() << endl;
Tridiagonalization(Index size=Size==Dynamic ? 2 :Size)
Default constructor.
Definition Tridiagonalization.h:120
Matrix< double, Dynamic, Dynamic > MatrixXd
Dynamic×Dynamic matrix of type double.
Definition Matrix.h:489

Output:

Here is a random symmetric 5x5 matrix:
-0.422  0.855  -1.12   1.21  0.648
 0.855 0.0536   1.44 0.0267  0.997
 -1.12   1.44 -0.396 -0.734 -0.859
  1.21 0.0267 -0.734   1.89   1.38
 0.648  0.997 -0.859   1.38    1.8

The orthogonal matrix Q is:
     1      0      0      0      0
     0 -0.434  0.468 0.0932 -0.764
     0  0.568 -0.431 -0.316 -0.625
     0 -0.617 -0.364 -0.697 0.0424
     0 -0.329  -0.68  0.637 -0.152
The tridiagonal matrix T is:
-0.422  -1.97      0      0      0
 -1.97   1.78   2.61      0      0
     0   2.61 -0.256 -0.317      0
     0      0 -0.317  0.435 -0.359
     0      0      0 -0.359   1.39

Q * T * Q^T = 
-0.422  0.855  -1.12   1.21  0.648
 0.855 0.0536   1.44 0.0267  0.997
 -1.12   1.44 -0.396 -0.734 -0.859
  1.21 0.0267 -0.734   1.89   1.38
 0.648  0.997 -0.859   1.38    1.8

◆ Tridiagonalization() [3/3]

template<typename MatrixType_>
template<typename InputType>
Eigen::Tridiagonalization< MatrixType_ >::Tridiagonalization ( EigenBase< InputType > & matrix)
inlineexplicit

Constructor for inplace decomposition .

Parameters
[in,out]matrixSelfadjoint matrix whose tridiagonal decomposition is to be computed.

When MatrixType is a Ref<>, the decomposition is computed within the memory of matrix, which then holds the packed representation returned by packedMatrix(). Otherwise this constructor behaves like Tridiagonalization(const EigenBase<InputType>&).

Member Function Documentation

◆ compute()

template<typename MatrixType_>
template<typename InputType>
Tridiagonalization & Eigen::Tridiagonalization< MatrixType_ >::compute ( const EigenBase< InputType > & matrix)
inline

Computes tridiagonal decomposition of given matrix.

Parameters
[in]matrixSelfadjoint matrix whose tridiagonal decomposition is to be computed.
Returns
Reference to *this

The tridiagonal decomposition is computed by bringing the columns of the matrix successively in the required form using Householder reflections. The cost is \( 4n^3/3 \) flops, where \( n \) denotes the size of the given matrix.

This method reuses the allocated data in the Tridiagonalization object, if the size of the matrix does not change.

Example:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
MatrixXf X = MatrixXf::Random(4, 4);
MatrixXf A = X + X.transpose();
tri.compute(A);
cout << "The matrix T in the tridiagonal decomposition of A is: " << endl;
cout << tri.matrixT() << endl;
tri.compute(2 * A); // reuse tri to compute eigenvalues of 2A
cout << "The matrix T in the tridiagonal decomposition of 2A is: " << endl;
cout << tri.matrixT() << endl;
MatrixTReturnType matrixT() const
Returns an expression of the tridiagonal matrix T in the decomposition.
Definition Tridiagonalization.h:275
Tridiagonalization & compute(const EigenBase< InputType > &matrix)
Computes tridiagonal decomposition of given matrix.
Definition Tridiagonalization.h:173
Matrix< float, Dynamic, Dynamic > MatrixXf
Dynamic×Dynamic matrix of type float.
Definition Matrix.h:488

Output:

The matrix T in the tridiagonal decomposition of A is: 
  1.36 -0.704      0      0
-0.704 0.0147   1.71      0
     0   1.71  0.856  0.641
     0      0  0.641 -0.506
The matrix T in the tridiagonal decomposition of 2A is: 
  2.72  -1.41      0      0
 -1.41 0.0294   3.43      0
     0   3.43   1.71   1.28
     0      0   1.28  -1.01

◆ diagonal()

template<typename MatrixType>
Tridiagonalization< MatrixType >::DiagonalReturnType Eigen::Tridiagonalization< MatrixType >::diagonal ( ) const

Returns the diagonal of the tridiagonal matrix T in the decomposition.

Returns
expression representing the diagonal of T
Precondition
Either the constructor Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal decomposition of a matrix.

Example:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
MatrixXcd X = MatrixXcd::Random(4, 4);
MatrixXcd A = X + X.adjoint();
cout << "Here is a random self-adjoint 4x4 matrix:" << endl << A << endl << endl;
MatrixXd T = triOfA.matrixT();
cout << "The tridiagonal matrix T is:" << endl << T << endl << endl;
cout << "We can also extract the diagonals of T directly ..." << endl;
VectorXd diag = triOfA.diagonal();
cout << "The diagonal is:" << endl << diag << endl;
VectorXd subdiag = triOfA.subDiagonal();
cout << "The subdiagonal is:" << endl << subdiag << endl;
Matrix< std::complex< double >, Dynamic, Dynamic > MatrixXcd
Dynamic×Dynamic matrix of type std::complex<double>.
Definition Matrix.h:491
Matrix< double, Dynamic, 1 > VectorXd
Dynamic×1 vector of type double.
Definition Matrix.h:489

Output:

Here is a random self-adjoint 4x4 matrix:
    (-0.422,0) (-0.17,-0.323)  (-0.3,-0.209)  (0.925,-1.66)
 (-0.17,0.323)      (-1.03,0)   (0.747,1.33) (-0.237,-0.98)
  (-0.3,0.209)  (0.747,-1.33)       (1.08,0)  (-1.26,-1.71)
  (0.925,1.66)  (-0.237,0.98)   (-1.26,1.71)       (1.88,0)

The tridiagonal matrix T is:
-0.422   1.97      0      0
  1.97  0.764  -2.31      0
     0  -2.31   2.22  -1.44
     0      0  -1.44  -1.05

We can also extract the diagonals of T directly ...
The diagonal is:
-0.422
 0.764
  2.22
 -1.05
The subdiagonal is:
 1.97
-2.31
-1.44
See also
matrixT(), subDiagonal()

◆ householderCoefficients()

template<typename MatrixType_>
CoeffVectorType Eigen::Tridiagonalization< MatrixType_ >::householderCoefficients ( ) const
inline

Returns the Householder coefficients.

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

The Householder coefficients allow the reconstruction of the matrix \( Q \) in the tridiagonal decomposition from the packed data.

Example:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
Matrix4d X = Matrix4d::Random(4, 4);
Matrix4d A = X + X.transpose();
cout << "Here is a random symmetric 4x4 matrix:" << endl << A << endl;
Vector3d hc = triOfA.householderCoefficients();
cout << "The vector of Householder coefficients is:" << endl << hc << endl;
Matrix< double, 3, 1 > Vector3d
3×1 vector of type double.
Definition Matrix.h:489
Matrix< double, 4, 4 > Matrix4d
4×4 matrix of type double.
Definition Matrix.h:489

Output:

Here is a random symmetric 4x4 matrix:
-0.422  0.705  -0.17  0.338
 0.705  0.515  0.241   0.05
 -0.17  0.241  -1.03 0.0449
 0.338   0.05 0.0449   1.36
The vector of Householder coefficients is:
1.88
1.82
   0
See also
packedMatrix(), Householder module

◆ matrixQ()

template<typename MatrixType_>
HouseholderSequenceType Eigen::Tridiagonalization< MatrixType_ >::matrixQ ( ) const
inline

Returns the unitary matrix Q in the decomposition.

Returns
object representing the matrix Q
Precondition
Either the constructor Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal 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.

See also
Tridiagonalization(const MatrixType&) for an example, matrixT(), class HouseholderSequence

◆ matrixT()

template<typename MatrixType_>
MatrixTReturnType Eigen::Tridiagonalization< MatrixType_ >::matrixT ( ) const
inline

Returns an expression of the tridiagonal matrix T in the decomposition.

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

Currently, this function can be used to extract the matrix T from internal data and copy it to a dense matrix object. In most cases, it may be sufficient to directly use the packed matrix or the vector expressions returned by diagonal() and subDiagonal() instead of creating a new dense copy matrix with this function.

See also
Tridiagonalization(const MatrixType&) for an example, matrixQ(), packedMatrix(), diagonal(), subDiagonal()

◆ packedMatrix()

template<typename MatrixType_>
const MatrixType & Eigen::Tridiagonalization< 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 Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal decomposition of a matrix.

The returned matrix contains the following information:

  • the strict upper triangular part is equal to the input matrix A.
  • the diagonal and lower sub-diagonal represent the real tridiagonal symmetric matrix T.
  • 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:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
Matrix4d X = Matrix4d::Random(4, 4);
Matrix4d A = X + X.transpose();
cout << "Here is a random symmetric 4x4 matrix:" << endl << A << endl;
Matrix4d pm = triOfA.packedMatrix();
cout << "The packed matrix M is:" << endl << pm << endl;
cout << "The diagonal and subdiagonal corresponds to the matrix T, which is:" << endl << triOfA.matrixT() << endl;

Output:

Here is a random symmetric 4x4 matrix:
-0.422  0.705  -0.17  0.338
 0.705  0.515  0.241   0.05
 -0.17  0.241  -1.03 0.0449
 0.338   0.05 0.0449   1.36
The packed matrix M is:
-0.422  0.705  -0.17  0.338
  -0.8  0.535  0.241   0.05
-0.113  0.683 -0.264 0.0449
 0.225  0.316 -0.914  0.573
The diagonal and subdiagonal corresponds to the matrix T, which is:
-0.422   -0.8      0      0
  -0.8  0.535  0.683      0
     0  0.683 -0.264 -0.914
     0      0 -0.914  0.573
See also
householderCoefficients()

◆ subDiagonal()

template<typename MatrixType>
Tridiagonalization< MatrixType >::SubDiagonalReturnType Eigen::Tridiagonalization< MatrixType >::subDiagonal ( ) const

Returns the subdiagonal of the tridiagonal matrix T in the decomposition.

Returns
expression representing the subdiagonal of T
Precondition
Either the constructor Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal decomposition of a matrix.
See also
diagonal() for an example, matrixT()

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