24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 562  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 085404总分289,求调剂 +3 Acesczlo 2026-03-29 3/150 2026-04-03 14:41 by 氮气气气
[考研] 344材料与化工调剂 +5 调剂上岸玘 2026-04-03 5/250 2026-04-03 14:32 by Mistake-J
[考研] 333求调剂 +9 wfh030413@ 2026-04-03 9/450 2026-04-03 14:20 by 啊俊!
[硕博家园] 求老师收留 +9 lllq123 2026-04-03 9/450 2026-04-03 13:48 by 呼吸都是减肥
[考研] 调剂 +7 祉岷. 2026-04-02 7/350 2026-04-03 09:11 by 花呗还欠600
[考研] 322求调剂:一志愿湖南大学 材料与化工(085600),已过六级。 +12 XX小邓 2026-03-29 13/650 2026-04-02 21:39 by 百灵童888
[考研] 0856材料与化工调剂,339 +14 10213207 2026-03-31 14/700 2026-04-02 21:01 by 1104338198
[考研] 293求调剂 +4 珂珂乐 2026-04-02 4/200 2026-04-02 20:10 by 6781022
[考研] 329求调剂 +8 miaodesi 2026-04-02 10/500 2026-04-02 10:24 by 不吃魚的貓
[考研] 303求调剂 +8 DLkz1314. 2026-03-30 8/400 2026-04-02 09:08 by sanrepian
[考研] 301求调剂 +13 A_JiXing 2026-04-01 13/650 2026-04-02 09:01 by sanrepian
[考研] 285求调剂 +11 AZMK 2026-04-01 11/550 2026-04-01 22:40 by peike
[考研] 0703一志愿南师大334求调剂 +4 seven7yu 2026-03-30 4/200 2026-04-01 16:10 by oooqiao
[考研] 求调剂 +4 图鉴212 2026-03-30 5/250 2026-04-01 15:32 by 图鉴212
[考研] 0710生物学求调剂! +6 叙述文 2026-03-31 6/300 2026-04-01 09:39 by JourneyLucky
[考研] 333求调剂 +4 阿科逸 2026-03-31 4/200 2026-04-01 09:11 by jp9609
[考研] 材料与化工272求调剂 +25 阿斯蒂芬2004 2026-03-28 25/1250 2026-03-31 16:27 by hypershenger
[考研] 276求调剂 +3 赵久华 2026-03-29 3/150 2026-03-31 10:06 by cal0306
[考研] 求调剂 +7 青春裁为三截 2026-03-29 7/350 2026-03-30 13:14 by laoshidan
[考研] 085405 考的11408求各位老师带走 +3 Qiu学ing 2026-03-28 3/150 2026-03-28 09:19 by 乐呵呵的追梦人
信息提示
请填处理意见