10#ifndef EIGEN_MATRIX_SQUARE_ROOT
11#define EIGEN_MATRIX_SQUARE_ROOT
19template <
typename MatrixType,
typename ResultType>
27 sqrtT.template block<2,2>(i,i)
34template <
typename MatrixType,
typename ResultType>
38 Scalar tmp = (sqrtT.row(i).segment(i+1,j-i-1) * sqrtT.col(j).segment(i+1,j-i-1)).
value();
39 sqrtT.coeffRef(i,j) = (T.coeff(i,j) - tmp) / (sqrtT.coeff(i,i) + sqrtT.coeff(j,j));
43template <
typename MatrixType,
typename ResultType>
49 rhs -= sqrtT.block(i, i+1, 1, j-i-1) * sqrtT.block(i+1, j, j-i-1, 2);
51 A += sqrtT.template block<2,2>(j,j).transpose();
52 sqrtT.template block<1,2>(i,j).transpose() = A.fullPivLu().solve(rhs.transpose());
56template <
typename MatrixType,
typename ResultType>
62 rhs -= sqrtT.block(i, i+2, 2, j-i-2) * sqrtT.block(i+2, j, j-i-2, 1);
64 A += sqrtT.template block<2,2>(i,i);
65 sqrtT.template block<2,1>(i,j) = A.fullPivLu().solve(rhs);
69template <
typename MatrixType>
74 coeffMatrix.
coeffRef(0,0) = A.coeff(0,0) + B.coeff(0,0);
75 coeffMatrix.
coeffRef(1,1) = A.coeff(0,0) + B.coeff(1,1);
76 coeffMatrix.
coeffRef(2,2) = A.coeff(1,1) + B.coeff(0,0);
77 coeffMatrix.
coeffRef(3,3) = A.coeff(1,1) + B.coeff(1,1);
78 coeffMatrix.
coeffRef(0,1) = B.coeff(1,0);
79 coeffMatrix.
coeffRef(0,2) = A.coeff(0,1);
80 coeffMatrix.
coeffRef(1,0) = B.coeff(0,1);
81 coeffMatrix.
coeffRef(1,3) = A.coeff(0,1);
82 coeffMatrix.
coeffRef(2,0) = A.coeff(1,0);
83 coeffMatrix.
coeffRef(2,3) = B.coeff(1,0);
84 coeffMatrix.
coeffRef(3,1) = A.coeff(1,0);
85 coeffMatrix.
coeffRef(3,2) = B.coeff(0,1);
94 result = coeffMatrix.fullPivLu().solve(rhs);
97 X.coeffRef(0,1) =
result.coeff(1);
98 X.coeffRef(1,0) =
result.coeff(2);
99 X.coeffRef(1,1) =
result.coeff(3);
103template <
typename MatrixType,
typename ResultType>
111 C -= sqrtT.block(i, i+2, 2, j-i-2) * sqrtT.block(i+2, j, j-i-2, 2);
114 sqrtT.template block<2,2>(i,j) = X;
119template <
typename MatrixType,
typename ResultType>
125 if (i ==
size - 1 || T.coeff(i+1, i) == 0) {
127 sqrtT.coeffRef(i,i) =
sqrt(T.coeff(i,i));
138template <
typename MatrixType,
typename ResultType>
143 if (T.coeff(j, j-1) != 0)
145 for (
Index i = j-1; i >= 0; i--) {
146 if (i > 0 && T.coeff(i, i-1) != 0)
148 bool iBlockIs2x2 = (i <
size - 1) && (T.coeff(i+1, i) != 0);
149 bool jBlockIs2x2 = (j <
size - 1) && (T.coeff(j+1, j) != 0);
150 if (iBlockIs2x2 && jBlockIs2x2)
152 else if (iBlockIs2x2 && !jBlockIs2x2)
154 else if (!iBlockIs2x2 && jBlockIs2x2)
156 else if (!iBlockIs2x2 && !jBlockIs2x2)
179template <
typename MatrixType,
typename ResultType>
203template <
typename MatrixType,
typename ResultType>
207 typedef typename MatrixType::Scalar Scalar;
214 for (
Index i = 0; i <
arg.rows(); i++) {
217 for (
Index j = 1; j <
arg.cols(); j++) {
218 for (
Index i = j-1; i >= 0; i--) {
220 Scalar tmp = (
result.row(i).segment(i+1,j-i-1) *
result.col(j).segment(i+1,j-i-1)).
value();
237template <typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex>
247 template <
typename ResultType>
static void run(
const MatrixType &
arg, ResultType &
result);
253template <
typename MatrixType>
257 template <
typename ResultType>
272 result = U * sqrtT * U.adjoint();
279template <
typename MatrixType>
283 template <
typename ResultType>
298 result = U * (sqrtT.template triangularView<Upper>() * U.adjoint());
335 template <
typename ResultType>
340 DerivedEvalType tmp(
m_src);
352template<
typename Derived>
359template <
typename Derived>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Definition: ArrayCwiseUnaryOps.h:66
EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedBlockXpr< internal::get_fixed_value< NRowsType >::value, internal::get_fixed_value< NColsType >::value >::Type block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols)
Definition: BlockMethods.h:96
EIGEN_DEVICE_FUNC RealReturnType real() const
Definition: CommonCwiseUnaryOps.h:100
#define eigen_assert(x)
Definition: Macros.h:1047
\eigenvalues_module
Definition: ComplexSchur.h:52
const ComplexMatrixType & matrixT() const
Returns the triangular matrix in the Schur decomposition.
Definition: ComplexSchur.h:162
const ComplexMatrixType & matrixU() const
Returns the unitary matrix in the Schur decomposition.
Definition: ComplexSchur.h:138
\eigenvalues_module
Definition: EigenSolver.h:65
EigenvectorsType eigenvectors() const
Returns the eigenvectors of given matrix.
Definition: EigenSolver.h:345
const EigenvalueType & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition: EigenSolver.h:244
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,...
Definition: PlainObjectBase.h:175
Proxy for the matrix square root of some matrix (expression).
Definition: MatrixSquareRoot.h:318
internal::ref_selector< Derived >::type DerivedNested
Definition: MatrixSquareRoot.h:320
Index cols() const
Definition: MatrixSquareRoot.h:345
const DerivedNested m_src
Definition: MatrixSquareRoot.h:348
void evalTo(ResultType &result) const
Compute the matrix square root.
Definition: MatrixSquareRoot.h:336
MatrixSquareRootReturnValue(const Derived &src)
Constructor.
Definition: MatrixSquareRoot.h:328
Index rows() const
Definition: MatrixSquareRoot.h:344
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,...
Definition: PlainObjectBase.h:152
\eigenvalues_module
Definition: RealSchur.h:55
const MatrixType & matrixU() const
Returns the orthogonal matrix in the Schur decomposition.
Definition: RealSchur.h:127
const MatrixType & matrixT() const
Returns the quasi-triangular matrix in the Schur decomposition.
Definition: RealSchur.h:144
Definition: ReturnByValue.h:52
void matrix_sqrt_quasi_triangular(const MatrixType &arg, ResultType &result)
Compute matrix square root of quasi-triangular matrix.
Definition: MatrixSquareRoot.h:180
void matrix_sqrt_triangular(const MatrixType &arg, ResultType &result)
Compute matrix square root of triangular matrix.
Definition: MatrixSquareRoot.h:204
auto sqrt(const UnitType &value) noexcept -> unit_t< square_root< typename units::traits::unit_t_traits< UnitType >::unit_type >, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the square root of value
Definition: math.h:483
void matrix_sqrt_quasi_triangular_1x2_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:44
void matrix_sqrt_quasi_triangular_solve_auxiliary_equation(MatrixType &X, const MatrixType &A, const MatrixType &B, const MatrixType &C)
Definition: MatrixSquareRoot.h:70
void matrix_sqrt_quasi_triangular_diagonal(const MatrixType &T, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:120
void matrix_sqrt_quasi_triangular_2x2_diagonal_block(const MatrixType &T, Index i, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:20
void matrix_sqrt_quasi_triangular_off_diagonal(const MatrixType &T, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:139
void matrix_sqrt_quasi_triangular_2x2_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:104
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
void matrix_sqrt_quasi_triangular_1x1_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:35
void matrix_sqrt_quasi_triangular_2x1_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:57
Namespace containing all symbols from the Eigen library.
Definition: MatrixExponential.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
result
Definition: format.h:2556
Definition: Eigen_Colamd.h:50
MatrixType::PlainObject PlainType
Definition: MatrixSquareRoot.h:256
static void run(const MatrixType &arg, ResultType &result)
Definition: MatrixSquareRoot.h:258
static void run(const MatrixType &arg, ResultType &result)
Definition: MatrixSquareRoot.h:284
MatrixType::PlainObject PlainType
Definition: MatrixSquareRoot.h:282
Helper struct for computing matrix square roots of general matrices.
Definition: MatrixSquareRoot.h:239
static void run(const MatrixType &arg, ResultType &result)
Compute the matrix square root.
T type
Definition: Meta.h:126
Derived::PlainObject ReturnType
Definition: MatrixSquareRoot.h:355
Definition: ForwardDeclarations.h:17