小编Tom*_*its的帖子

新手问题 - 使用 Eigen 的复杂矩阵代数

我是 C++ 新手,正在尝试将以下 MATLAB 代码转换为 C++:

x = [1,2,3];
y = [4,5,7];
px = 0.5;
py = 0.5;

m = -1:1:1;

v = [1+i,2+i,3+i;1+2i,2+2i,3+2i;1+3i,2+3i,3+3i];

Tr5 = real(exp(2i*pi/px*x(1)*m)*v*exp(2i*pi/py*m'*y(1)));

fprintf('Tr5 = %f\n',Tr5);
Run Code Online (Sandbox Code Playgroud)

返回 Tr5=18。

这是我在 C++ 中的尝试,我在每一行都尽可能少地尝试寻找错误:

#include <Eigen/Dense>
#include <unsupported/Eigen/MatrixFunctions>
#include <math.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <complex>
#include <iostream>

int main()
{

double x [3] = {1, 2, 3};
double y [3] = {4, 5, 7};
const std::complex<double> im(0.0, 1.0);
double px = 0.5;
double py = 0.5; …
Run Code Online (Sandbox Code Playgroud)

c++ eigen

2
推荐指数
1
解决办法
197
查看次数

标签 统计

c++ ×1

eigen ×1