1、/*采用了调整因子的规则表,大误差时偏重误差,小误差时偏重误差变化*/ /*a0=0.3,a1=0.55,a2=0.74,a3=0.89 */int rule77= /误差变化率 -3,-2,-1, 0, 1, 2, 3 / 误差 -6,-6,-6,-5,-5,-5,-4, / -3 -5,-4,-4,-3,-2,-2,-1, -2 -4,-3,-2,-1, 0, 1, 2, -1 -4,-3,-1, 0, 1, 3, 4, 0 -2,-1, 0, 1, 2, 3, 4, 1 1, 2, 2, 3, 4, 4, 5, 2 4, 5, 5, 5, 6, 6, 6; 3/*/int Fuzzy(i
2、nt P,int D) /*模糊运算引擎*/ U; /*偏差,偏差微分以及输出值的精确量*/ unsigned int PF2,DF2,UF4; /*偏差,偏差微分以及输出值的隶属度*/ Pn,Dn,Un4;long temp1,temp2;/*隶属度的确定*/ /*根据PD的指定语言值获得有效隶属度*/ if(P-PFF3 & PPFF3) if(P=-PFF2) Pn=-2; PF0=FMAX*(float)(-PFF2-P)/(PFF3-PFF2); else if(P=-PFF1) Pn=-1; PF0=FMAX*(float)(-PFF1-P)/(PFF2-PFF1); =PFF0)
3、 Pn=0; PF0=FMAX*(float)(-PFF0-P)/(PFF1-PFF0);=PFF1) Pn=1; PF0=FMAX*(float)(PFF1-P)/(PFF1-PFF0);=PFF2) Pn=2; PF0=FMAX*(float)(PFF2-P)/(PFF2-PFF1);=PFF3) Pn=3; PF0=FMAX*(float)(PFF3-P)/(PFF3-PFF2); else if(P PF0=0;PF1=FMAX-PF0;if(D-DFF3 & DDFF3) if(D=-DFF2) Dn=-2;DF0=FMAX*(float)(-DFF2-D)/(DFF3-DFF2);
4、 else if(D=-DFF1) Dn=-1; DF0=FMAX*(float)(-DFF1-D)/(DFF2-DFF1);=DFF0) Dn=0; DF0=FMAX*(float)(-DFF0-D)/(DFF1-DFF0);=DFF1) Dn=1; DF0=FMAX*(float)(DFF1-D)/(DFF1-DFF0);=DFF2) Dn=2; DF0=FMAX*(float)(DFF2-D)/(DFF2-DFF1);=DFF3) Dn=3; DF0=FMAX*(float)(DFF3-D)/(DFF3-DFF2);else if(D DF0=0;DF1=FMAX-DF0;/*使用误差范
5、围优化后的规则表rule77*/ /*输出值使用13个隶属函数,中心值由UFF7指定*/ /*一般都是四个规则有效*/ Un0=rulePn-1+3Dn-1+3;Un1=rulePn+3Dn-1+3;Un2=rulePn-1+3Dn+3;Un3=rulePn+3Dn+3;if(PF0=DF0) UF0=PF0;else UF0=DF0;if(PF1UF1) UF1=0; else UF0=0;if(Un0=Un2)UF2) UF2=0;if(Un0=Un3)UF3) UF3=0; elseif(Un1=Un2) if(UF1if(Un1=Un3)if(Un2=Un3) if(UF2/*重心法反
6、模糊*/ /*Un原值为输出隶属函数标号,转换为隶属函数值*/ if(Un0=0) Un0=UFFUn0; Un0=-UFF-Un0;if(Un1 Un1=UFFUn1; Un1=-UFF-Un1;if(Un2 Un2=UFFUn2;else Un2=-UFF-Un2;if(Un3 Un3=UFFUn3; Un3=-UFF-Un3;temp1=UF0*Un0+UF1*Un1+UF2*Un2+UF3*Un3;temp2=UF0+UF1+UF2+UF3;U=temp1/temp2;return U;void main()int a=0,e,ec;/*int nowpoint,p1,p2=1;FILE *in,*out;in=fopen(in.txt,r);out=fopen(out.txtw*/while(!feof(in)while(1) /fscanf(in,%d,&nowpoint); /p1=nowpoint; /e=0-nowpoint; /ec= p1-p2; printf(请输入e: scanf(e);请输入ec:ec); a=Fuzzy(e,ec); /fprintf(out,%d ,a); /printf(%d:,p1);e: %d ec:,e,ec);a: n /p2=p1;/fclose(in);/fclose(out);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1