如何获得输出中带有'i'(虚值)的复数的输出
how to get output of complex number with 'i' (imaginary value ) in the output
这是我在c++中使用bluestein算法的代码4fft计算
#include <iostream>
#include <cmath>
#include <complex>
#define pi 3.14
using namespace std;
int main()
{
int n, k, N;
std::complex<double> y, z, sum = 0, x[] = { 1, 2, 2, 1 };
int i = sqrt(-1);
N = 4;
for (k = 0; k <= N - 1; k++)
{
y = exp(pi*k*N*k*i);
for (n = 0; n <= N - 1; n++)
{
z = exp((pi*(k*k - 2 * k*n*i)) / N);
sum += (x[n] * z);
}
x[k] = (sum * y);
cout << "The fft of x[n] is = " << x[k] << endl;
}
return 0;
}
当v在visualstudio2013中运行时,我需要输出为{6,-1-i,0,-1+j}。如果可能的话,plz可以帮助我一般地声明输入数组。
<lt;运算符是这样重载的http://en.cppreference.com/w/cpp/numeric/complex/operator_ltltgtgt
然而,您可以使用它来获得所需的输出:
cout << "The fft of x[n] is = " << x[k].real() << "+"<< x[k].imag()<< "i" << endl;
相关文章:
- 在多次运行中获得一致的callgrind输出
- 在我的代码中,获得最大的Pair Wise产品C++和输出并不总是正确的
- 未获得字符串中的预期输出
- 在黑客地球上没有获得以下C ++代码问题的输出
- 使用OpenMP获得完整、无损坏的输出需要什么
- 我不明白我的编译器是如何获得此输出的
- 尝试从多态函数中获得不同的输出
- 无效* 转换获得意外输出
- 未获得 N-皇后问题的预期输出
- 我无法从中获得输出
- 为什么每次在 openmp 代码中获得不同的输出?
- C++程序未获得所需的输出
- 需要帮助我如何获得不同的输出
- C++ - 未获得控制台的预期输出
- 输出时获得的奇怪值
- 使用 ofstream 进行缓冲文本输出以获得性能
- c++在标准输入上写入数据,并从标准输出中获得输出
- 如何在Linux上的c++中将数据管道到bzip2中并从其标准输出中获得结果数据?
- 如何在C中显示输出时获得链表索引
- 如何在当前时间的打印输出中获得更高的精度(几分之一秒)