c语言实现傅里叶级数展开
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
if(!text(sum,x)) {
printf("验证结果不相符,可能傅里叶级数展开有错!\n"); } else {
printf("验证结果相符,傅里叶级数展开正确!\n"); }
return 0; }
double Geta(double Low,double Up,double step,double m,int p,int s) {
int i,n=1; double s1=0,s2=0,sum1=0,sum2=0;
while(n<=p) {
for(i=1;i<=s;i++) { s1=s1+(Low+(i-0.5)*step)*(Low+(i-0.5)*step)*cos(n*(Low+(i-0.5)*step)); s2=s2+(Low+(i-0.5)*step)*(Low+(i-0.5)*step)*sin(n*(Low+(i-0.5)*step)); } sum1+=s1*step*cos(n*m); sum2+=s2*step*sin(n*m); s1=0; s2=0; n++; }
double st; double x,sum; int ps,n;
printf("请输入区间个数:"); scanf("%d",&ps); st=(u-l)/ps; printf("请输入傅里叶展开的项数:"); scanf("%d",&n); printf("请输入你要求的数:");源自文库scanf("%lf",&x); printf("x^2 的傅里叶展开得到的结果为:"); sum=Getb(l,u,st,ps)/2+Geta(l,u,st,x,n,ps); printf("%lf\n",sum);
#include<stdio.h> #include<math.h>
double Getb(double Low,double Up,double step,int s) {
int i; double sum=0;
for(i=0;i<s;i++) {
sum=sum+(Low+(i+1/2)*step)*(Low+(i+1/2)*step); } return step*sum/Up; }
return (sum1+sum2)/Up; }
double text(double t,double x) {
double e=0.00001; if(fabs(t-x*x)<=e) {
return true; }
return false; }
int main(void) {
double l=-3.1415926; double u=3.1415926;
printf("验证结果不相符,可能傅里叶级数展开有错!\n"); } else {
printf("验证结果相符,傅里叶级数展开正确!\n"); }
return 0; }
double Geta(double Low,double Up,double step,double m,int p,int s) {
int i,n=1; double s1=0,s2=0,sum1=0,sum2=0;
while(n<=p) {
for(i=1;i<=s;i++) { s1=s1+(Low+(i-0.5)*step)*(Low+(i-0.5)*step)*cos(n*(Low+(i-0.5)*step)); s2=s2+(Low+(i-0.5)*step)*(Low+(i-0.5)*step)*sin(n*(Low+(i-0.5)*step)); } sum1+=s1*step*cos(n*m); sum2+=s2*step*sin(n*m); s1=0; s2=0; n++; }
double st; double x,sum; int ps,n;
printf("请输入区间个数:"); scanf("%d",&ps); st=(u-l)/ps; printf("请输入傅里叶展开的项数:"); scanf("%d",&n); printf("请输入你要求的数:");源自文库scanf("%lf",&x); printf("x^2 的傅里叶展开得到的结果为:"); sum=Getb(l,u,st,ps)/2+Geta(l,u,st,x,n,ps); printf("%lf\n",sum);
#include<stdio.h> #include<math.h>
double Getb(double Low,double Up,double step,int s) {
int i; double sum=0;
for(i=0;i<s;i++) {
sum=sum+(Low+(i+1/2)*step)*(Low+(i+1/2)*step); } return step*sum/Up; }
return (sum1+sum2)/Up; }
double text(double t,double x) {
double e=0.00001; if(fabs(t-x*x)<=e) {
return true; }
return false; }
int main(void) {
double l=-3.1415926; double u=3.1415926;