24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 560  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 303求调剂 +3 一色清羽 2026-04-02 4/200 2026-04-03 10:22 by 蓝云思雨
[考研] 320求调剂 +4 振—TZ 2026-04-02 4/200 2026-04-03 09:56 by 何曾几何
[考研] 复试调剂 +4 春日来信- 2026-04-03 4/200 2026-04-03 08:36 by JourneyLucky
[考研] 调剂 +3 osbbx 2026-04-02 3/150 2026-04-03 07:47 by cc8418
[考研] 285求调剂 +8 AZMK 2026-04-02 11/550 2026-04-02 20:16 by yulian1987
[考研] 求生物学调剂 +10 15172915737 2026-04-01 10/500 2026-04-02 18:53 by 哦哦嗯哈
[考研] 一志愿南昌大学324求调剂 +12 hanamiko 2026-04-01 12/600 2026-04-02 14:51 by 5896
[考研] 一志愿北京科技大学材料学硕328分求调剂 +6 1段时间 2026-03-31 7/350 2026-04-02 13:57 by 3041
[考研] 08生物与医药专硕初试346找调剂 +6 dianeeee 2026-04-01 7/350 2026-04-02 08:23 by guoweigw
[考研] 一志愿安徽大学计算机科学与技术学硕,331分求调剂 +5 蒋昌鹏qtj 2026-04-01 5/250 2026-04-02 08:10 by fxue1114
[考研] 江苏科技大学招材料研究生 +4 Su032713. 2026-04-01 5/250 2026-04-01 22:03 by cccchenso
[考研] 08工科,295,接受跨专业调剂 +6 lmnlzy 2026-03-31 6/300 2026-04-01 11:02 by 逆水乘风
[考研] 318求调剂 +8 七忆77 2026-04-01 8/400 2026-04-01 10:37 by Jaylen.
[考研] 322求调剂 +8 三水sss 2026-04-01 8/400 2026-04-01 10:19 by 唐沐儿
[考研] 环境工程 085701,267求调剂 +15 minht 2026-03-29 16/800 2026-04-01 10:13 by li_sujuan99
[考研] 求调剂 +9 akdhjs 2026-03-31 10/500 2026-03-31 17:14 by zhyzzh
[考研] 329求调剂,一志愿西北工业大学,材料工程(085601) +6 小小机灵虫 2026-03-29 12/600 2026-03-31 16:58 by 记事本2026
[考研] 一志愿南昌大学324求调剂 +6 hanamiko 2026-03-29 6/300 2026-03-31 16:35 by hypershenger
[考研] 材料工程专硕求调剂 +10 hyl3153942 2026-03-29 10/500 2026-03-31 16:31 by hypershenger
[考研] 11408总分309,一志愿东南大学求调剂,不挑专业 +5 天赋带到THU 2026-03-29 6/300 2026-03-30 20:49 by dick_runner
信息提示
请填处理意见