繁体   English   中英

如何在输出中获取带有'i'(虚值)的复数输出

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM