[英]How do I calculate the exponential of a complex matrix?
我在尝试使用 C++ Eigen 库计算复杂矩阵的指数时遇到问题。
下面是我尝试制作的示例代码。
#include <iostream>
#include "Dense"
#include <complex>
#include "unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h"
int main()
{
using namespace std::complex_literals;
Eigen::MatrixXcd test(2,2);
test(0,0)=1i+std::complex<double>(5);
test(1,0)=1i*2.;
test(0,1)=std::complex<double>(2);
test(1,1)=3.*1i+std::complex<double>(3);
std::cout << "The matrix exponential is:\n"
<< test.exp() << "\n\n";
}
当我运行这个程序时,我得到了错误:
Implicit instantiation of undefined template 'Eigen::MatrixFunctionReturnValue<Eigen::Matrix<std::__1::complex<double>, -1, -1, 0, -1, -1> >'
我试图找到答案,但我还没有找到答案。
任何帮助将不胜感激。
编辑:
Eigen 工作中的标准矩阵运算和 Eigen 文件/文件夹位于我的项目文件夹中。 唯一似乎不起作用的函数是复杂矩阵不受支持的文件夹中的矩阵函数(它们确实适用于真实矩阵)。
您不能直接包含来自Eigen/src
或unsupported/Eigen/src
子目录的标题。 此外,使用#include <Eigen/Dense>
代替#include "Dense"
(在许多情况下<Eigen/Core>
实际上就足够了)。
在您的情况下,您实际上只需要这些包含,因为MatrixFunctions
包含所有必要的依赖项:
#include <iostream>
#include <unsupported/Eigen/MatrixFunctions>
Godbolt-Demo: https://godbolt.org/z/PmJWP3 (编译可能偶尔会超时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.