[英]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.