31 #include <Eigen/Dense> 32 #include <Eigen/Eigenvalues> 42 assert(A.rows() == C.rows());
43 assert(B.rows() == C.cols());
51 Eigen::MatrixXcd T_A = A_schur.matrixT();
52 const Eigen::MatrixXcd& U_A = A_schur.matrixU();
53 const Eigen::MatrixXcd& T_B = B_schur.
matrixT();
54 const Eigen::MatrixXcd& U_B = B_schur.
matrixU();
56 const int n = C.rows();
57 const int m = C.cols();
60 Eigen::MatrixXcd F = U_A.adjoint() * C * U_B;
62 Eigen::MatrixXcd Y(n, m);
70 for (
int k = 0; k < m; ++k)
72 Eigen::VectorXcd rhs = F.col(k) + Y * T_B.col(k);
74 const std::complex<double> offset = T_B(k, k);
75 T_A.diagonal().array() += offset;
81 Y.col(k) = T_A_svd.
solve(-rhs);
83 if (k < mm) T_A.diagonal().array() -= offset;
87 X = (U_A * Y * U_B.adjoint()).
real();
96 Eigen::VectorXcd eigvals_A = A.eigenvalues();
97 Eigen::VectorXcd eigvals_B = B.eigenvalues();
99 for (
int i = 0; i < eigvals_A.size(); ++i)
101 for (
int j = 0; j < eigvals_B.size(); ++j)
bool approx_equal(double a, double b, double epsilon=1e-6)
Check if two doubles are appoximately equal.
bool is_square(const Eigen::MatrixBase< Derived > &matrix)
Determine if a given matrix is square.
ComputationInfo info() const
Reports whether previous computation was successful.
const Solve< JacobiSVD< _MatrixType, QRPreconditioner >, Rhs > solve(const MatrixBase< Rhs > &b) const
static bool solve(const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::MatrixXd > &B, const Eigen::Ref< const Eigen::MatrixXd > &C, Eigen::MatrixXd &X)
Solve continuous-time Sylvester equation.
MatrixType A(a, *n, *n, *lda)
static bool hasUniqueSolution(const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::MatrixXd > &B)
Determine if the Sylvester equation exhibits a unique solution.
A matrix or vector expression mapping an existing expression.
const ComplexMatrixType & matrixU() const
Returns the unitary matrix in the Schur decomposition.
Two-sided Jacobi SVD decomposition of a rectangular matrix.
JacobiSVD & compute(const MatrixType &matrix, unsigned int computationOptions)
Method performing the decomposition of given matrix using custom options.
EIGEN_DEVICE_FUNC const ImagReturnType imag() const
MatrixType B(b, *n, *nrhs, *ldb)
Performs a complex Schur decomposition of a real or complex square matrix.
const ComplexMatrixType & matrixT() const
Returns the triangular matrix in the Schur decomposition.