[英]How are complex numbers(and the imaginary number i) represented in Native C as opposed to C++?
[英]how to get output of complex number with 'i' (imaginary value ) in the output
這是我在C ++中使用bluestein算法的代碼4 fft calc
#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在Visual Studio 2013中運行時,我需要輸出為{6,-1-i,0,-1 + j}。如果可能,請plz幫助我總體上聲明輸入數組。
<<操作符會像這樣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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.