Sistema difuso.
Enviado por tonyd1591 • 18 de Mayo de 2016 • Tarea • 817 Palabras (4 Páginas) • 79 Visitas
PARA TODOS LOS EJERCICIOS
FUNCIONES DE ENTRADA
[pic 1]
REGLAS
SI (ANGULO) | ENTONCES (MOTOR) |
I(IZQUIERDA) | RN(RAPIDO NEGATIVO) |
MI(MEDIO IZQUIERDA) | LN(LENTO NEGATIVO) |
C(CENTRADO) | ID(IDEAL) |
MD(MEDIO DERECHA) | LP(LENTO POSOTIVO) |
D(DERECHA) | RP(RAPIDO POSITIVO) |
EJERCICIO 1 MAMDANI
CODIGO
clc
clear all
close all
dx=0.5
An=[-360:dx:360];
x=[-100:100];
%%%%%%%%%%%%%% entrada en angulo
I=trap(An,-360,-360,-300,-150);
MI=tri(An,-300,-150,0);
C=tri(An,-50,0,50);
MD=tri(An,0,150,300);
D=trap(An,150,300,360,360);
%%%%%%%%%%%%%% grafica de la entrada
hold on
plot(An,I,'b')
plot(An,MI,'r')
plot(An,C,'k')
plot(An,MD,'g')
plot(An,D,'c')
grid on
hold off
%%%%%%%%%%%%%%%%%%%%% salida del motor
RN=trap(x,-100,-100,-80,-40);
LN=tri(x,-80,-40,0);
I=tri(x,-20,0,20);
LP=tri(x,0,40,80);
RP=trap(x,40,80,100,100);
%%%%%%%%%%%%%%%% grafica de las salidas
figure
hold on
plot(x,RN,'b')
plot(x,LN,'r')
plot(x,I,'k')
plot(x,LP,'g')
plot(x,RP,'c')
grid on
hold off
%%%%%%%%%%%%%%%% calculo de membresias
m1=0;
m2=0;
m3=0;
m4=0;
m5=0;
a=input('valor del angulo:');
if(a<-300)
m1=1;
elseif(a<-150 && a>=-300)
m1= (-150-a)/150;
m2= (a+300)/150;
elseif (a<=0 && a>=-150)
m2=(0-a)/150;
if(a>-50 && a<=0)
m3=(a+50)/50;
m2=(0-a)/150;
end
elseif(a>0 && a<150)
m4=a/150;
if (a>0 && a<50)
m3=(50-a)/50;
end
elseif(a>=150 && a<=300)
m4= (300-a)/150;
m5= (a-150)/150;
elseif (a>=300)
m5=1;
end
m=[m1 m2 m3 m4 m5]
%%%%%%%%%%%%% mamdani maxima
if(m1>m2)
VM=-80
elseif(m2>m3 && m2>m1)
VM=-40
elseif(m2
VM=0
elseif(m3
VM=40
elseif(m5>m4)
VM=80
end
%%%%%%%%%%%%%%%%%%% mamdani centroide
for i=1:length(RN)
if RN(i)<=m1
RNF(i)=RN(i);
else
RNF(i)=m1;
end
end
for i=1:length(LN)
if LN(i)<=m2
LNF(i)=LN(i);
else
LNF(i)=m2;
end
end
for i=1:length(I)
if I(i)<=m3
IF(i)=I(i);
else
IF(i)=m3;
end
end
for i=1:length(LP)
if LP(i)<=m4
LPF(i)=LP(i);
else
LPF(i)=m4;
end
end
for i=1:length(RP)
if RP(i)<=m5
RPF(i)=RP(i);
else
RPF(i)=m5;
end
end
figure
hold on
plot(x,RNF,'b')
plot(x,LNF,'r')
plot(x,IF,'g')
plot(x,LPF,'r')
plot(x,RPF,'b')
hold off
for i=1:length(x)
s2(i)=max(max(max(max(RPF(i),LPF(i)),IF(i)),RNF(i)),LNF(i));
end
figure,plot(x,s2)
VM1=sum(s2.*x.*dx)/sum(s2.*dx)
%%%%%%%%%%%%%%%% mamdani media de centros
VM2=((-80*m1)+(-40*m2)+(0*m3)+(40*m4)+(80*m5))/(m1+m2+m3+m4+m5)
FUNCION DE SALIDA
[pic 2]
EJERCICIO 2 SUGENO
CODIGO
clc
clear all
close all
dx=0.5
An=[-360:dx:360];
x=[-100:100];
%%%%%%%%%%%% entrada en angulo
I=trap(An,-360,-360,-300,-150);
...