MatrixSquareRoot.cpp 434 B

12345678910111213141516
  1. #include <unsupported/Eigen/MatrixFunctions>
  2. #include <iostream>
  3. using namespace Eigen;
  4. int main()
  5. {
  6. const double pi = std::acos(-1.0);
  7. MatrixXd A(2,2);
  8. A << cos(pi/3), -sin(pi/3),
  9. sin(pi/3), cos(pi/3);
  10. std::cout << "The matrix A is:\n" << A << "\n\n";
  11. std::cout << "The matrix square root of A is:\n" << A.sqrt() << "\n\n";
  12. std::cout << "The square of the last matrix is:\n" << A.sqrt() * A.sqrt() << "\n";
  13. }