📄 fuzzy01.c
字号:
/* fuzzy01.c */
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <math.h>
float Gas_NM[] = {
1, 0.8, 0.6, 0.4, 0.2, 0, 0, 0, 0, 0, 0
};
float Gas_Z[] = {
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0
};
float Gas_PM[] = {
0, 0, 0, 0, 0, 0, 0.2, 0.4, 0.6, 0.8, 1
};
int Gas_output;
void GAS_OUT(int T)
{
int i;
float map_i, v_i, area, moment;
float u_T;
float *u_Gas;
/*** 癘拘砰皌竚 ***/
u_Gas = (float *) calloc(11,sizeof(float));
/*************** 砏玥 1 ***************/
/* T IS PM */
u_T=0.0;
if ((T>=74) & (T<=86))
u_T=(float)(T-74)/12;
printf("Rule 1: %f\n",u_T);
/* Gas = NM */
if (u_T != 0.0) {
for (i=0; i<11; i++) {
u_Gas[i] = max(u_Gas[i], min(u_T, Gas_NM[i]));
}
}
/*************** 砏玥 2 ***************/
/* T IS Z */
u_T=0.0;
if ((T>=60) & (T<=70))
u_T=(float)(T-60)/10;
if ((T>70) & (T<=80))
u_T=(float)(80-T)/10;
printf("Rule 2: %f\n",u_T);
/* Gas = Z */
if (u_T != 0.0) {
for (i=0; i<11; i++) {
u_Gas[i] = max(u_Gas[i], min(u_T, Gas_Z[i]));
}
}
/************** 砏玥 3 ****************/
/* T IS NM */
u_T=0.0;
if ((T>=54) & (T<=66))
u_T=(float)(66-T)/12;
printf("Rule 3: %f\n",u_T);
/* Gas = PM */
if (u_T != (float)0) {
for (i=0; i<11; i++) {
u_Gas[i] = max(u_Gas[i], min(u_T, Gas_PM[i]));
}
}
/************* 秆家絢て *****************/
area = 0.0;
moment = 0.0;
for(i=0; i<11; i++) {
map_i = u_Gas[i];
printf("i = %2d, map_i = %f\n", i, map_i);
v_i = -5 + i;
area += map_i;
moment += map_i * v_i;
}
printf("\narea=%f monent=%f\n",area, moment);
if (area == 0) { /* 磷
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -