#include <stdio.h>
#include <fstream>
#include <cstdio.h>
float pe1,pe2,pe_1,pe_2,u_1[4],u_cm[4];
float e1,e2,e_1,Temp_Set,Temp_Scan,U_Temp=0;
#define E1_With 20 //误差三角形宽度的一半
#define E_1_With 0.1//微分三角形宽度的一半
#define U_With 40//控制量宽度的一半
#ifndef Slope_E //误差的斜率
#define Slope_E 0.05
#endif
#ifndef Slope_E_1//微分的斜率
#define Slope_E_1 10
#endif
/*float Ruler[7][7]={
{-3*U_With,-3*U_With,-3*U_With,-3*U_With,-3*U_With,-2*U_With,-2*U_With},
{-3*U_With,-3*U_With,-3*U_With,-3*U_With,-2*U_With,-2*U_With,-2*U_With},
{-3*U_With,-3*U_With,-3*U_With,-2*U_With,-2*U_With,-2*U_With,-2*U_With},
{-3*U_With,-3*U_With,-2*U_With,-2*U_With,-2*U_With,-2*U_With,-1*U_With},
{-1*U_With,-1*U_With,-1*U_With,0*U_With,0*U_With,0*U_With,0*U_With },
{0*U_With,0*U_With,0*U_With,1*U_With,1*U_With,1*U_With,2*U_With },
{1*U_With,1*U_With,2*U_With,2*U_With,2*U_With,3*U_With,3*U_With }
};*/
float Ruler[7][7]={ // 规则表
{-120, -120, -120, -120, -120, -80, -80 },
{-120, -120, -120, -120, -80, -80, -80 },
{-120, -120, -120, -80, -40, 0, 0 },
{-80, -80, -40, 0, 40, 40, 40 },
{0, 0, 40, 40, 40, 40, 40 },
{0, 40, 40, 40, 40, 40, 80 },
{40, 40, 80, 80, 80, 120, 120 }
};
void f1(float x);
void f2(float y);
void f3();
void f4(float x,float y);
void f5();
void fuzzy(float x,float y);
void main()
{
/*ifstream infile("f1.txt",ios::in);
outfile.open(;
if(!infile)
{cerr<<"open error!"<<endl;
exit(1);
}*/
//float k=0.1;
e1=-120;
Temp_Set=300;
Temp_Scan=280;
printf("%10s","误差 ");
printf("%s"," ");
printf("%10s","误差微分");
printf("%s"," ");
printf("%10s","控制量");
printf("\n");
while(1)
{
while (e1<150)
{e1=Temp_Scan-Temp_Set;
//e_1=(e1-e2)/0.1;
e2=e1;
e_1=-0.4;
while(e_1<0.4)
{
fuzzy(e1,e_1);
printf("%10f",e1);
printf("%s"," ");
printf("%10f",e_1);
printf("%s"," ");
printf("%f\n",U_Temp);
e_1=e_1+0.01;
}
Temp_Scan=Temp_Scan+0.5;
}
}
}
void f1(float i)//求解误差的隶属度
{if (i>=3*E1_With)
{pe1=1;pe2=0;}
else if (i>=2*E1_With)
{pe1=Slope_E*(i-2*E1_With);pe2=-Slope_E*(i-3*E1_With);}
else if (i>=E1_With)
{pe1=Slope_E*(i-E1_With);pe2=-Slope_E*(i-2*E1_With);}
else if (i>=0)
{pe1=Slope_E*i;pe2=-Slope_E*(i-E1_With);}
else if (i>=-E1_With)
{pe1=Slope_E*(i+E1_With);pe2=-Slope_E*i;}
else if (i>=-2*E1_With)
{pe1=Slope_E*(i+2*E1_With);pe2=-Slope_E*(i+E1_With);}
else if (i>=-3*E1_With)
{pe1=Slope_E*(i+3*E1_With);pe2=-Slope_E*(i+2*E1_With);}
else
{pe1=0;pe2=1;}
}
void f2(float i) //求解误差微分的隶属度
{if (i>=3*E_1_With)
{pe_1=1;pe_2=0;}
else if (i>=2*E_1_With)
{pe_1=Slope_E_1*(i-2*E_1_With);pe_2=-Slope_E_1*(i-3*E_1_With);}
else if (i>=E_1_With)
{pe_1=Slope_E_1*(i-E_1_With);pe_2=-Slope_E_1*(i-2*E_1_With);}
else if (i>=0)
{pe_1=Slope_E_1*i;pe_2=-Slope_E_1*(i-E_1_With);}
else if (i>=-E_1_With)
{pe_1=Slope_E_1*(i+E_1_With);pe_2=-Slope_E_1*i;}
else if (i>=-2*E_1_With)
{pe_1=Slope_E_1*(i+2*E_1_With);pe_2=-Slope_E_1*(i+E_1_With);}
else if (i>=-3*E_1_With)
{pe_1=Slope_E_1*(i+3*E_1_With);pe_2=-Slope_E_1*(i+2*E_1_With);}
else
{pe_1=0;pe_2=1;}
}
void f3 ()//计算规则的隶属度(乘积)
{if (pe1==1 && pe2==1)
if (pe_1==1 && pe_2==1)
{u_1[0]=1;
u_1[1]=0;
u_1[2]=0;
u_1[3]=0;
}
else
{u_1[0]=pe_1;
u_1[1]=pe_2;
u_1[2]=0;
u_1[3]=0;
}
else
{ /*if(pe2==1)
{ u_1[0]=pe2*pe_1;
u_1[1]=pe2*pe_2;
u_1[2]=pe1*pe_1;
u_1[3]=pe1*pe_2;
}
else
{
*/
u_1[0]=pe1*pe_1;
u_1[1]=pe1*pe_2;
u_1[2]=pe2*pe_1;
u_1[3]=pe2*pe_2;
//}Ruler[][]
}
}
void f4(float i,float j)//求解输出中心
{ if (i>=3*E1_With)
if (j>=3*E_1_With)
//u_cm=[-120,0,0,0];
{ u_cm[ 0]=Ruler[0][0];u_cm[1]=0;u_cm[2]=0;u_cm[3]=0; }
else if (j>=2*E_1_With)
//u_cm=[-120,-120,0,0];
{ u_cm[0]=Ruler[0][0];u_cm[1]=Ruler[0][1];u_cm[2]=0;u_cm[3]=0; }
else if (j>=E_1_With)
//u_cm=[-120,-120,0,0];
{ u_cm[0]=Ruler[0][1];u_cm[1]=Ruler[0][2];u_cm[2]=0;u_cm[3]=0; }
else if (j>=0)
//u_cm=[-120,-120,0,0];
{ u_cm[0]=Ruler[0][2];u_cm[1]=Ruler[0][3];u_cm[2]=0;u_cm[3]=0; }
else if (j>=-E_1_With)
//u_cm=[-120,-120,0,0];
{ u_cm[0]=Ruler[0][3];u_cm[1]=Ruler[0][4];u_cm[2]=0;u_cm[3]=0; }
else if (j>=-2*E_1_With)
//u_cm=[-120,-80,0,0];
{ u_cm[0]=Ruler[0][4];u_cm[1]=Ruler[0][5];u_cm[2]=0;u_cm[3]=0; }
else if (j>=-3*E_1_With)
//u_cm=[-80,-80,0,0];
{ u_cm[0]=Ruler[0][5];u_cm[1]=Ruler[0][6];u_cm[2]=0;u_cm[3]=0; }
else
//u_cm=[-80,0,0,0];
{ u_cm[0]=0;u_cm[1]=Ruler[0][6];u_cm[2]=0;u_cm[3]=0; }
else if (i>=2*E1_With)
if (j>=3*E_1_With)
//u_cm=[-120,-120,0,0];
{ u_cm[0]=Ruler[0][0];u_cm[1]=0;u_cm[2]=Ruler[1][0];u_cm[3]=0; }
else if (j>=2*E_1_With)
//u_cm=[-120,-120,-120,-120];
{ u_cm[0]=Ruler[0][0];u_cm[1]=Ruler[0][1];u_cm[2]=Ruler[1][0];u_cm[3]=Ruler[1][1]; }
else if (j>=E_1_With)
//u_cm=[-120,-120,-120,-120];
{ u_cm[0]=Ruler[0][1];u_cm[1]=Ruler[0][2];u_cm[2]=Ruler[1][1];u_cm[3]=Ruler[1][2]; }
else if (j>=0)
//u_cm=[-120,-120,-120,-120];
{ u_cm[0]=Ruler[0][2];u_cm[1]=Ruler[0][3];u_cm[2]=Ruler[1][2];u_cm[3]=Ruler[1][3]; }
else if (j>=-E_1_With)
//u_cm=[-120,-120,-120,-80];
{ u_cm[0]=Ruler[0][3];u_cm[1]=Ruler[0][4];u_cm[2]=Ruler[1][3];u_cm[3]=Ruler[1][4];}
else if (j>=-2*E_1_With)
// u_cm=[-120,-80,-80,-80];
{ u_cm[0]=Ruler[0][4];u_cm[1]=-Ruler[0][5];u_cm[2]=Ruler[1][4];u_cm[3]=Ruler[1][5]; }
else if (j>=-3*E_1_With)
//u_cm=[-80,-80,-80,-80];
{ u_cm[0]=Ruler[0][5];u_cm[1]=Ruler[0][6];u_cm[2]=Ruler[1][5];u_cm[3]=Ruler[1][6]; }
else
// u_cm=[-80,-80,0,0];
{ u_cm[0]=0;u_cm[1]=Ruler[0][6];u_cm[2]=0;u_cm[3]=Ruler[1][6]; }
else if(i>=E1_With)
if (j>=3*E_1_With)
// u_cm=[-120,0,-120,0];
{ u_cm[0]=Ruler[1][0];u_cm[1]=0;u_cm[2]=Ruler[2][0];u_cm[3]=0; }
else if (j>=2*E_1_With)
// u_cm=[-120,-120,-120,-120];
{ u_cm[0]=Ruler[1][0];u_cm[1]=Ruler[1][1];u_cm[2]=Ruler[2][0];u_cm[3]=Ruler[2][1]; }
else if (j>=E_1_With)
// u_cm=[-120,-120,-120,-120];
{ u_cm[0]=Ruler[1][1];u_cm[1]=Ruler[1][2];u_cm[2]=Ruler[2][1];u_cm[3]=Ruler[2][2]; }
else if (j>=0)
// u_cm=[-120,-120,-120,-80];
{ u_cm[0]=Ruler[1][2];u_cm[1]=Ruler[1][3];u_cm[2]=Ruler[2][2];u_cm[3]=Ruler[2][3]; }
else if (j>=-E_1_With)
//u_cm=[-120,-80,-80,-80];
{ u_cm[0]=Ruler[1][3];u_cm[1]=Ruler[1][4];u_cm[2]=Ruler[2][3];u_cm[3]=Ruler[2][4]; }
else if (j>=-2*E_1_With)
// u_cm=[-80,-80,-80,-80];
{ u_cm[0]=Ruler[1][4];u_cm[1]=Ruler[1][5];u_cm[2]=Ruler[2][4];u_cm[3]=Ruler[2][5]; }
else if (j>=-3*E_1_With)
// u_cm=[-80,-80,-80,-80];
{ u_cm[0]=Ruler[1][5];u_cm[1]=Ruler[1][6];u_cm[2]=Ruler[2][5];u_cm[3]=Ruler[2][6]; }
else
{ u_cm[0]=0;u_cm[1]=Ruler[1][6];u_cm[2]=0;u_cm[3]=Ruler[2][6]; }
else if(i>=0)
if (j>=3*E_1_With)
// u_cm=[-120,0,-120,0];
{ u_cm[0]=Ruler[2][0];u_cm[1]=0;u_cm[2]=Ruler[3][0];u_cm[3]=0; }
else if (j>=2*E_1_With)
// u_cm=[-120,-120,-120,-120];
{ u_cm[0]=Ruler[2][0];u_cm[1]=Ruler[2][1];u_cm[2]=Ruler[3][0];u_cm[3]=Ruler[3][1]; }
else if (j>=E_1_With)
//u_cm=[-120,-120,-120,-80];
{ u_cm[0]=Ruler[2][1];u_cm[1]=Ruler[2][2];u_cm[2]=Ruler[3][1];u_cm[3]=Ruler[3][2]; }
else if (j>=0)
//u_cm=[-120,-80,-80,-80];
{ u_cm[0]=Ruler[2][2];u_cm[1]=Ruler[2][3];u_cm[2]=Ruler[3][2];u_cm[3]=Ruler[3][3]; }
else if (j>=-E_1_With)
// u_cm=[-80,-80,-80,-80];
{ u_cm[0]=Ruler[2][3];u_cm[1]=Ruler[2][4];u_cm[2]=Ruler[3][3];u_cm
- 1
- 2
- 3
- 4
前往页