24小时热门版块排行榜    

查看: 663  |  回复: 4

zhanglei22

银虫 (小有名气)

[交流] 【求助】帮忙看看程序!谢谢了【已完结】 已有2人参与

这是fft的程序 运行中出了问题 不知哪的错误
#include
#include
#include
#define N 1000
typedef struct
{
        double real;
    double img;
} complex;

void fft();          //快速傅里叶变换
void initw();
void change();

void add(complex,complex,complex *);
void mul(complex,complex,complex *);
void sub(complex,complex,complex *);
void output();

complex x(N),*w;
int size_x=0;
double PI;

int main()
{
        int i,method;
        void fft();
        void initw();
        void change();
    void add(complex,complex,complex *);
    void mul(complex,complex,complex *);
    void sub(complex,complex,complex *);
    void divi(complex,complex,complex *);

        PI=atan(1)*4;
        printf("please input the size of x:\n";
        scanf("%d",&size_x);
        printf("please input the date in x(N):\n";
        for(i=0;i         scanf("%lf%lf",&x.real,&x.img);
        initw();
        output();
        return 0;
}

void fft()
{
        int i=0,j=0,k=0,l=0;
        complex up,down,product;
        change();
        for(i=0;i         {
                l=1<                 for(j=0;j                 {
                        for(k=0;k                         {
                                mul(x[j+k+l],w[size_x*k/2/l],&product);
                                add(x[j+k],product,&up);
                                sub(x[j+k],product,&down);
                                x[j+k]=up;
                                x[j+k+l]=down;
                        }
                }
        }
}

void initw()
{
        int i;
        w=(complex *)malloc(sizeof(complex)*size_x);
        for(i=0;i         {
                w.real=cos(2*PI/size_x*i);
                w.img=-1*sin(2*PI/size_x*i);
        }
}

void change()
{
        complex temp;
        unsigned short i=0,j=0,k=0;
        double t;
        for(i=0;i         {
                k=1;j=0;
                t=(log(size_x)/log(2));
                while((t--)>0)
                {j=j<<1;j|=(k&1);k=k>>1;}
                if(j>1)
                {temp=x;x=x[j];x[j]=temp;}
        }
}

void output()
{
        int i;
        printf("the result are as follows \n";
        for(i=0;i         {
                printf("%.4f",x.real);
                if(x.img>=0.0001)
                        printf("+%.4f\n",x.img);
                else if(fabs(x.img)<0.0001)
                        printf("\n";
                else printf("%.4f\n",x.img);
        }
}

void add(complex a,complex b,complex *c)
{
        c->real=a.real+b.real;
        c->img=a.img+b.img;
}

void mul(complex a,complex b,complex *c)
{
        c->real=a.real*b.real-a.img*b.img;
        c->img=a.real*b.img+a.img*b.real;
}

void sub(complex a,complex b,complex *c)
{
        c->real=a.real-b.real;
        c->img=a.img-b.img;
}

[ Last edited by 余泽成 on 2010-6-2 at 16:23 ]
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

magic7004

金虫 (职业作家)

★
resonant(金币+1):感谢参与。 2010-06-01 15:04:01
zhanglei22(金币+5): 2010-06-02 14:57:45
晕,楼主至少要说一下是什么样的错误吧

是编译不过,还是运行时崩溃,还是计算结果不对?
如果是前两个的话,顺便把错误信息也贴出来
如果是后一个的话,懂FFT的来吧,我只懂C,不懂计算
流氓不可怕,可怕的是流氓有文化,有文化又BH的流氓无敌~~!
2楼2010-06-01 14:36:21
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhanglei22

银虫 (小有名气)

是 程序错误
3楼2010-06-02 14:43:06
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhanglei22

银虫 (小有名气)

ompiling...
fft.cpp
D:\vc\FFT\fft.cpp(22) : error C2440: 'initializing' : cannot convert from 'const int' to 'complex'
        No constructor could take the source type, or constructor overload resolution was ambiguous
D:\vc\FFT\fft.cpp(42) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(42) : error C2228: left of '.real' must have class/struct/union type
D:\vc\FFT\fft.cpp(42) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(42) : error C2228: left of '.img' must have class/struct/union type
D:\vc\FFT\fft.cpp(60) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(61) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(62) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(63) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(64) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(93) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(93) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(93) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(93) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(103) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(103) : error C2228: left of '.real' must have class/struct/union type
D:\vc\FFT\fft.cpp(104) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(104) : error C2228: left of '.img' must have class/struct/union type
D:\vc\FFT\fft.cpp(105) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(105) : error C2228: left of '.img' must have class/struct/union type
D:\vc\FFT\fft.cpp(106) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(106) : error C2228: left of '.img' must have class/struct/union type
D:\vc\FFT\fft.cpp(108) : error C2676: binary '[' : 'complex' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\vc\FFT\fft.cpp(108) : error C2228: left of '.img' must have class/struct/union type
执行 cl.exe 时出错.

FFT.exe - 1 error(s), 0 warning(s)
这个错误!
4楼2010-06-02 14:44:12
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhanglei22

银虫 (小有名气)

呃~ 发现了 数组定义出错了 谢谢了
5楼2010-06-02 14:57:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zhanglei22 的主题更新
普通表情 龙 兔 虎 猫 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考博] 售SCI一区文章,我:8.O.551.O.5.4,科目全,可伽急 +3 hKe7U1kad5Sg 2026-10-31 6/300 2026-11-02 12:25 by n0P4fnsXKbBK
[考研] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +3 hKe7U1kad5Sg 2026-10-31 6/300 2026-11-02 12:20 by n0P4fnsXKbBK
[考博] 售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急 +3 BCdvBAEpt3zm 2026-11-01 4/200 2026-11-02 10:23 by dcc2yOIRGGTT
[考研] 售SCI一区T0P文章,我:8.O.55.1.O.54,科目齐全,可+急 +4 hKe7U1kad5Sg 2026-10-31 7/350 2026-11-02 09:29 by dcc2yOIRGGTT
[基金申请] 各位基础老师们,看完中央《从严治党》的决定后,对学术界更加有信心了吧 +3 iaeyuan 2026-11-01 3/150 2026-11-02 07:49 by kudofaye
[公派出国] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +4 hKe7U1kad5Sg 2026-10-31 6/300 2026-11-02 06:20 by xzcv0Tehd8lQ
[公派出国] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 xvJS1BYDxvBS 2026-10-31 8/400 2026-11-02 06:07 by xzcv0Tehd8lQ
[论文投稿] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +4 1uaZt2kAZj2S 2026-10-30 14/700 2026-11-02 05:41 by xzcv0Tehd8lQ
[公派出国] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +4 1uaZt2kAZj2S 2026-10-30 17/850 2026-11-02 05:34 by xzcv0Tehd8lQ
[论文投稿] 售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急 +3 hKe7U1kad5Sg 2026-10-31 5/250 2026-11-02 03:39 by xzcv0Tehd8lQ
[找工作] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +5 1uaZt2kAZj2S 2026-10-31 9/450 2026-11-02 03:05 by xzcv0Tehd8lQ
[硕博家园] 售SCI一区T0P文章,我:8.O.55.1.O.54,科目齐全,可+急 +6 X5bHxOULxFqb 2026-10-30 16/800 2026-11-02 02:34 by xzcv0Tehd8lQ
[找工作] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 hKe7U1kad5Sg 2026-10-31 5/250 2026-11-01 22:27 by xzcv0Tehd8lQ
[公派出国] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +4 1uaZt2kAZj2S 2026-10-30 8/400 2026-11-01 21:35 by xzcv0Tehd8lQ
[公派出国] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +4 1uaZt2kAZj2S 2026-10-30 15/750 2026-11-01 16:52 by BCdvBAEpt3zm
[考博] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +5 X5bHxOULxFqb 2026-10-30 22/1100 2026-11-01 16:35 by BCdvBAEpt3zm
[公派出国] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +4 1uaZt2kAZj2S 2026-10-31 7/350 2026-11-01 12:40 by BCdvBAEpt3zm
[考博] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 10/500 2026-11-01 12:27 by BCdvBAEpt3zm
[考研] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 +3 1uaZt2kAZj2S 2026-10-30 16/800 2026-11-01 12:14 by BCdvBAEpt3zm
[硕博家园] 申博自荐 2篇一区TOP+1篇EI+2公开发明专利 2027博士申请 +3 小小阿光 2026-10-27 3/150 2026-10-29 23:56 by 起风了的快乐
信息提示
请填处理意见