C++ 高斯函数的FFT;不确定在何处/如何插入值的打印语句

C++ 高斯函数的FFT;不确定在何处/如何插入值的打印语句,c++,printf,C++,Printf,所以,我最近才开始使用FFTW,我正在高斯曲线上试用它。一切都编译得很好(当直接完成时,还没有尝试调用make),但我希望它打印我的值,我不确定这些语句在我的代码中放在哪里;我也不熟悉C/C++的工作。这是我的代码: #include <stdio.h> #include <stdlib.h> #include <complex.h> #include <math.h> #include "fftw3.h"

所以,我最近才开始使用FFTW,我正在高斯曲线上试用它。一切都编译得很好(当直接完成时,还没有尝试调用make),但我希望它打印我的值,我不确定这些语句在我的代码中放在哪里;我也不熟悉C/C++的工作。这是我的代码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <complex.h>
    #include <math.h>
    #include "fftw3.h"

    int main(int argc, const char* argv[])
    {

      double complex *in, *out, *data;

      fftw_plan p;

      int i,j;
      int w=20;
      int h=20;
      double a = 2;
      double *x=malloc(i*j*sizeof(double));
      in = (double complex*) fftw_malloc(sizeof(double complex) * w * h);
      out = (double complex*) fftw_malloc(sizeof(double complex) * w * h);
        for(i=0; i<w; i++){
            for(j=0; j<h; j++){
                int temp = i*i+j*j;
                in[i*h+j] = exp(-(temp)/(a*a));
            }
        }
        p = fftw_plan_dft_2d(w, h, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
        fftw_execute(p);

        fftw_destroy_plan(p);
        fftw_free(in);
        fftw_free(out);
        return 0;
#包括
#包括
#包括
#包括
#包括“fftw3.h”
int main(int argc,const char*argv[]
{
双复数*输入,*输出,*数据;
fftw_计划p;
int i,j;
int w=20;
int h=20;
双a=2;
double*x=malloc(i*j*sizeof(double));
in=(双复合物*)fftw_malloc(双复合物)*w*h;
out=(双复合物*)fftw_malloc(双复合物的尺寸)*w*h);

对于(i=0;i您可以将打印代码放在fftw_执行之后和fftw_空闲之前的任何位置

请注意,您在分配x时有一个错误-您需要使用w和h作为大小,而不是i和j。尽管仔细检查,您的代码中甚至没有使用x,所以您可能应该去掉这个分配


还注意到,你的代码看起来是纯C,而不是C++。你应该编译它为C,而不投MALOC的结果。< /P>不是我的下投票,但是你希望在帮助之前至少尝试过一些东西。我没有投票,但是除了保罗的情感,我猜这是因为这更多的与<代码> CUT<代码>有关。(或

printf
)比使用
fftw
,除非你问的是某种理论问题。啊,好吧。我继续,删除了fftw标记,并进行了一些尝试编辑。我以为我使用了w和h作为大小?x和y是执行FFT后我要打印的值。仔细查看malloc调用,在那里为
x.
    printf("x=[");
        for(i=0; i<w; i++) printf("%15.7g",x[i]);
        printf("];\w\w");

        printf("y=[");
        for(j=0; j<h; j++) printf("%15.7g + %15.7gi", 1./((double) w)*creal(out[i], 1./((double) h)*cimag(out[j]);
        printf("];\h\h");
    printf("x=[");
        for(i=0; i<w; i++) printf("%15.7g",x[i]);
        printf("]");

        printf("y=[");
        for(j=0; j<h; j++) printf("%15.7g + %15.7gi", 1./((double) w)*creal(out[i], 1./((double) h)*cimag(out[j])));
        printf("]");