资源描述:
《傅里叶级数展开matlab实现.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、傅里叶级数展开matlab实现给个例子说明下:将函数y=x*(x-pi)*(x-2*pi),在(0,2*pi)的范围内傅里叶级数展开symsxfx=x*(x-pi)*(x-2*pi);[an,bn,f]=fseries(fx,x,12,0,2*pi)%前12项展开latex(f)%将f转换成latex代码an=[0,0,0,0,0,0,0,0,0,0,0,0,0]bn=[-12,3/2,-4/9,3/16,-12/125,1/18,-12/343,3/128,-4/243,3/250,-12/1331,1/14
2、4]f=12*sin(x)+3/2*sin(2*x)+4/9*sin(3*x)+3/16*sin(4*x)+12/125*sin(5*x)+1/18*sin(6*x)+12/343*sin(7*x)+3/128*sin(8*x)+4/243*sin(9*x)+3/250*sin(10*x)+12/1331*sin(11*x)+1/144*sin(12*x)ans=12,sinleft(xright)+3/2,sinleft(2,xright)+4/9,sinleft(3,xright
3、)+3/16,sinleft(4,xright)+{frac{12}{125}},sinleft(5,xright)+1/18,sinleft(6,xright)+{frac{12}{343}},sinleft(7,xright)+{frac{3}{128}},sinleft(8,xright)+{frac{4}{243}},sinleft(9,xright)+{frac{3}{250}},sinleft(10,xright)+{
4、frac{12}{1331}},sinleft(11,xright)+{frac{1}{144}},sinleft(12,xright)function[an,bn,f]=fseries(fx,x,n,a,b)%傅里叶级数展开%%an为fourier余弦项系数%bn为fourier正弦项系数%f为展开表达式%f为给定函数%x为自变量%n为展开系数%a,b为x的区间,默认为[-pi,pi]ifnargin==3a=-pi;b=pi;endl=(b-a)/2;ifa+bfx=subs(fx,x
5、,x+l+a);endan=int(fx,x,-l,l)/l;bn=[];f=an/2;forii=1:nann=int(fx*cos(ii*pi*x/l),x,-l,l)/l;bnn=int(fx*sin(ii*pi*x/l),x,-l,l)/l;an=[an,ann];bn=[bn,bnn];f=f+ann*cos(ii*pi*x/l)+bnn*sin(ii*pi*x/l);endifa+bf=subs(f,x,x-l-a);end%%%%%%%%%%%%%%%%%%%%【原创】MATLAB求解符号表达式数
6、值的方法:subs函数首先说明一下,使用的函数是subs,如果你已经知道了,就没必要继续往下看了,浪费时间,O(∩_∩)O首先是调用格式:R=subs(S)R=subs(S,new)R=subs(S,old,new)其中S为符号表达式,默认的是变量x!下面看几个例子,相信大家就是使用了!例1:>>symsx;>>f=x^2;>>subs(f,2)ans=4例2:将表达式x^2+y^2中x取值为2>>symsxy;>>f=x^2+y^2;>>subs(f,x,2)ans=y^2+4例3:>>symsxy;>>f=
7、x^2+y^2;>>subs(f,findsym(f),2)ans=y^2+4其中findsym(f)为查找f中所有的符号变量例4:同时对两个或多个变量取值求解>>symsab;subs(cos(a)+sin(b),{a,b},{sym('alpha'),2})ans=sin(2)+cos(alpha)例5:带入数据的值也可以是数组形式>>symsta;>>subs(exp(a*t),'a',-magic(2))ans=[1/exp(t),1/exp(3*t)][1/exp(4*t),1/exp(2*t)]