资源描述:
《基于matlab的函数逼近.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1设计一个在U=[-1,1]×[-1,1]上的模糊系统,使其以精度ε=0.1一致地逼近函数,并进行matlab仿真。解:根据题目要求,知,L=2,T=0.1,可取h=0.05,N=L/h+1=21程序如下所示:%Fuzzyapproachingclearall;closeall;T=0.1;x1=-1:T:1;x2=-1:T:1;L=2;h=0.05;N=L/h+1;fori=1:1:N%NMFforj=1:1:Ne1(i)=-1+L/(N-1)*(i-1);e2(j)=-1+L/(N-1)*(j-
2、1);gx(i,j)=sin((e1(i))*pi)+cos((e2(j))*pi)+sin(e1(i)*pi)*cos(e2(j)*pi)endenddf=zeros(L/T+1,L/T+1);cf=zeros(L/T+1,L/T+1);form=1:1:N%u1changefrom1toNifm==1u1=trimf(x1,[-1,-1,-1+L/(N-1)]);%Firstu1elseifm==Nu1=trimf(x1,[1-L/(N-1),1,1]);%Lastu1elseu1=trimf(
3、x1,[e1(m-1),e1(m),e1(m+1)]);endfigure(1);holdon;plot(x1,u1);xlabel('x1');ylabel('Membershipfunction');forn=1:1:N%u2changefrom1toNifn==1u2=trimf(x2,[-1,-1,-1+L/(N-1)]);%Firstu2elseifn==Nu2=trimf(x2,[1-L/(N-1),1,1]);%Lastu2elseu2=trimf(x2,[e2(n-1),e2(n),
4、e2(n+1)]);endfigure(2);holdon;plot(x2,u2);xlabel('x2');ylabel('Membershipfunction');fori=1:1:L/T+1forj=1:1:L/T+1d=df(i,j)+u1(i)*u2(j);df(i,j)=d;c=cf(i,j)+gx(m,n)*u1(i)*u2(j);cf(i,j)=c;endendendend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5、%%%%%%%%%fori=1:1:L/T+1forj=1:1:L/T+1f(i,j)=cf(i,j)/df(i,j);y(i,j)=sin((x1(i))*pi)+cos((x2(j))*pi)+sin(x1(i)*pi)*cos(x2(j)*pi)endendfigure(3);subplot(211);surf(x1,x2,f);title('f(x)');subplot(212);surf(x1,x2,y);title('g(x)');figure(4);surf(x1,x2,f-y);ti
6、tle('Approachingerror')x1和x2的隶属函数及g(x)的逼近效果如下图所示:图1x1的隶属函数图2x2的隶属函数图3模糊逼近图4逼近误差