/* User Guide --------------------------------------------------------------*/ /* c:\tc\the4_new>dt_old>dt_old.m */ /* Note: dt_old.m is the default o/p filename */ /*--------------------------------------------------------------------------*/ #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define L 0.66 #define SPACE ( -1.0/(3.0*(L-1.0)) ) float fs[7][2]={ {-1.0,SPACE}, {-2.0/3.0,SPACE}, {-1.0/3.0,SPACE}, {0.0,SPACE}, {1.0/3.0,SPACE}, {2.0/3.0,SPACE}, {1.0,SPACE} }; int frule[7][7]={ {3,4,4,5,5,6,6}, {2,3,4,4,5,5,6}, {2,2,3,4,4,5,5}, {1,2,2,3,4,4,5}, {1,1,2,2,3,4,4}, {0,1,1,2,2,3,4}, {0,0,1,1,2,2,3} }; float outy[25]={-1.2,-1.1,-1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0.0, 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2}; float dy_final[25]; float dny[7][25],dy[7][25]; float decision_t[25][25]; FILE *fout1; float B(float,float,float); float fmax(float,float); float fmin(float,float); void F_y_build(float,int); void F_y_final(); float seven_max(float,float,float,float,float,float,float); void main (void) { int i,j,k; int p,q; float e,ce; float be,bce; float tou; int out_s; float temp_n,temp_d; /*-------------- dny[][] determination ----------------------------------*/ for(i=0; i<7; i++) /* { printf("dny[%d][]=\n",i); */ for(j=0; j<25; j++) { dy[i][j]=0.0; dny[i][j]=B(outy[j],fs[i][0],fs[i][1]); /* printf("%6.3f",dny[i][j]); */ } /* printf("\n"); } */ /* -------------------- begin FIS --------------------------------------*/ for(i=0; i<25; i++) for(j=0; j<25; j++) { ce=outy[i]; e=outy[j]; for(p=0; p<7; p++) for(q=0; q<7; q++) { out_s=frule[p][q]; bce=B(ce,fs[p][0],fs[p][1]); be=B(e,fs[q][0],fs[q][1]); tou=fmin(bce,be); F_y_build(tou,out_s); } F_y_final(); temp_n=temp_d=0.0; for(k=0; k<25; k++) { temp_n+= outy[k]*dy_final[k]; temp_d+= dy_final[k]; } decision_t[i][j]= temp_n/temp_d; for(p=0; p<7; p++) for(q=0; q<25; q++) dy[p][q]=0.0; } for(i=0; i<25; i+=2) { /* printf("Decision_Table[%d][]:\n",i); */ for(j=0; j<25; j+=2) printf("%8.5f", decision_t[i][j]); printf("\n"); } } /* ------- Func. for calculating the result of each rule ------------------*/ void F_y_build(float t, int os) { int i; float dy_inter[25]; for(i=0; i<25; i++) dy_inter[i]=fmin(t,dny[os][i]); for(i=0; i<25; i++) dy[os][i]=fmax(dy_inter[i],dy[os][i]); } /* ------- Func. for calculating the result of all rules ------------------*/ void F_y_final(void) { int i; for(i=0; i<25; i++) dy_final[i]=seven_max(dy[0][i],dy[1][i],dy[2][i],dy[3][i],dy[4][i],dy[5][i],dy[6][i]); } /*------ Func. for finding membership func. (triangular) degree ----------*/ float B(float x, float a, float b) { if( (x<(a+b/2)) && (x>(a-b/2)) ) return(1-2*fabs(x-a)/b); else return(0); } /*------ Func. for finding max. of two values -----------------------------*/ float fmax(float a, float b) { if(a>b) return(a); else return(b); } /*------ Func. for finding min. of two values -----------------------------*/ float fmin(float a, float b) { if(a>b) return(b); else return(a); } /*---- Func. for finding max. of seven values ------------------------------*/ float seven_max(float a, float b, float c, float d, float e, float f, float g) { float p,q,r; float u,v,w; p=fmax(a,b); q=fmax(c,d); r=fmax(e,f); u=fmax(p,q); v=fmax(r,g); w=fmax(u,v); return(w); }