⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fuzzy02.c

📁 針對單輸入與雙輸入模糊溫度控制系統
💻 C
字号:
/* fuzzy02.c */
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <math.h>

float Gas_NM[] = {
    1.0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

float Gas_NS[] = {
    0, 0, 0.5, 1.0, 0.5, 0, 0, 0, 0, 0, 0
};

float Gas_Z[] = {
    0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0
};

float Gas_PS[] = {
    0, 0, 0, 0, 0, 0, 0.5, 1.0, 0.5, 0, 0
};

float Gas_PM[] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 1.0
};

float Gas_output;

void GAS_OUT(int T, int dT)
{
	int i;
	float map_i, v_i, area, moment;
	float t001;
   float ut_nm,ut_z,ut_pm;
   float dt_nm,dt_z,dt_pm;
	float *O_Gas;

	O_Gas = (float *) calloc(11,sizeof(float));

   /* T is NM */
   ut_nm=0.0;
   if (T >= 54 && T <= 66)
		ut_nm = (float)(66-T)/12;

   /* T is Z */
   ut_z=0.0;
   if ((T>=60) && (T<=70))
   	ut_z=(float)(T-60)/10;
   if (T>70 && T<=80)
   	ut_z=(float)(80-T)/10;

   /* T is PM */
   ut_pm=0.0;
   if (T>=74 && T<=86)
   	ut_pm=(float)(T-74)/12;

  /* dT is NM */
  dt_nm=0.0;
  if (dT>=-10 && dT<=-2)
  	dt_nm=(float)-(dT+2)/8;

  /* dT is Z */
  dt_z=0.0;
  if (dT>=-7 && dT <= 0)
  	dt_z=(float)(dT+7)/7;
  if (dT>0 && dT<=7)
  	dt_z=(float)(7-dT)/7;

  /* dT is PM */
  dt_pm=0.0;
  if (dT>=2 && dT<=10)
  	dt_pm=(float)(dT-2)/8;


	/***************  Rule1  ***************/
	/* T IS  PM and dT IS PM*/
  	t001 = min(ut_pm, dt_pm);    /* AND */
   printf("\nRule 1: %f\n", t001);

	/* Gas =  NM */
	if (t001 != 0.0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_NM[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule2  ***************/
	/* T IS  PM and dT IS Z */
   t001 = min(ut_pm, dt_z);    /* AND */
   printf("Rule 2: %f\n", t001);

	/* Gas =  NS */
	if (t001 != 0.0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_NS[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule3  ***************/
	/* T IS  PM and dT IS NM */
	t001 = min(ut_pm,dt_nm);    /* AND */
   printf("Rule 3: %f\n", t001);

	/* Gas =  Z */
	if (t001 != (float)0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_Z[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule4  ***************/
	/* T IS  Z and dT IS PM */
	t001 = min(ut_z,dt_pm);    /* AND */
   printf("Rule 4: %f\n", t001);

	/* Gas =  NS */
	if (t001 != (float)0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_NS[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule5  ***************/
	/* T IS  Z and dT is Z */
	t001 = min(ut_z,dt_z);    /* AND */
   printf("Rule 5: %f\n", t001);

	/* Gas =  Z */
	if (t001 != (float)0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_Z[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule6  ***************/
	/* T IS  Z and dT IS NM*/
	t001 = min(ut_z,dt_nm);    /* AND */
   printf("Rule 6: %f\n", t001);

	/* Gas =  PS */
	if (t001 != (float)0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_PS[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule7  ***************/
	/* T IS  NM and dT IS PM */
	t001 = min(ut_nm,dt_pm);    /* AND */
   printf("Rule 7: %f\n", t001);

	/* Gas =  Z */
	if (t001 != (float)0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_Z[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule8  ***************/
	/* T IS  NM and dT IS Z*/
	t001 = min(ut_nm,dt_z);    /* AND */
   printf("Rule 8: %f\n", t001);

	/* Gas =  PS */
	if (t001 != (float)0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_PS[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***************  Rule9  ***************/
	/* T IS  NM and dT IS NM*/
	t001 = min(ut_nm,dt_nm);    /* AND */
   printf("Rule 9: %f\n", t001);

	/* Gas =  PM */
	if (t001 != (float)0)  {
		for (i=0; i<11; i++) {
			map_i = (float)Gas_PM[i];
			O_Gas[i] = max(O_Gas[i], min(t001, map_i));
		}
	}

	/***** Calculate crisp value for variable Gas ******/
	area = 0.0;  moment = 0.0;
	for(i=0; i<11; i++)  {
		map_i = O_Gas[i];
      printf("i=%2d map_i=%f\n", i, map_i);
		v_i   = -5.0 + (float)i;
		area += map_i;
		moment += map_i * v_i;
	}
	if (area == 0) { /* Divide by zero error */
		Gas_output = 5.0;
	}
	else
		Gas_output = (moment / area);
	free(O_Gas);
}

int main(void)
{
  GAS_OUT(64, -5);
  printf("\nT=64, dT=-5, output = %f\n", Gas_output);
  GAS_OUT(64, 0);
  printf("\nT=64, dT= 0, output = %f\n", Gas_output);
  GAS_OUT(64, 5);
  printf("\nT=64, dT= 5, output = %f\n", Gas_output);
  getchar();
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -