Professional Documents
Culture Documents
clear;
close all;
clc;
% For A and B:
x = 0:1:10;
A = [0 0.7 0.3 0.9 1 0 0 0 0 0];
B = [0.2 0.4 0.1 0 0 0 0 0 0 0];
P1 = min(A,B);
P2 = max(A,B);
P3 = 1 - A;
P4 = 1 - B;
1
% Problem 1: Part (b)
figure;
subplot(221);
stem(A);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: Plot of A');
legend('A');
subplot(222);
stem(B);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: Plot of B');
legend('B');
subplot(223);
stem(A);
hold on
stem(B);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: Plot of A and B');
legend('A','B');
subplot(224);
stem(P2);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: max(A,B)');
legend('max(A,B)');
2
title('Problem 1: Plot of A and B');
legend('A','B');
subplot(224);
stem(P3);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: min(A,B)');
legend('1 - A');
figure;
subplot(221);
stem(A);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: Plot of A');
legend('A');
subplot(222);
stem(B);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: Plot of B');
legend('B');
subplot(223);
stem(A);
hold on
stem(B);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: Plot of A and B');
legend('A','B');
subplot(224);
stem(P4);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: min(A,B)');
legend('1 - B');
3
4
5
Assignment 4: Dated - 03/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
% light
Light = trimf(W,[10 25 40]);
E1(:,1) = Light;
E2{1,1} = 'Light';
% very light
VLight = trimf(W,[20 25 33]);
E1(:,2) = VLight;
E2{2,1} = 'Very Light';
% normal
Normal = trimf(W,[30 45 60]);
E1(:,3) = Normal;
E2{3,1} = 'Normal';
% middle
Middle = trimf(W,[30 45 60]);
E1(:,4) = Middle;
E2{4,1} = 'Middle';
% heavy
Heavy = trimf(W,[50 80 120]);
E1(:,5) = Heavy;
E2{5,1} = 'Heavy';
% very heavy
VHeavy = trimf(W,[70 80 100]);
E1(:,6) = VHeavy;
E2{6,1} = 'Very Heavy';
% massive
Massive = trimf(W,[110 150 190]);
E1(:,7) = Massive;
E2{7,1} = 'Massive';
figure;
plot(W,[VLight Light Normal Middle Heavy VHeavy Massive]);
ylim([0 1]);
xlabel('Weight (in Kg)');
ylabel('Membership Grades');
title('Problem 2: Plot of various membership functions');
legend('Very Light','Light','Normal','Middle','Heavy','Very Heavy','Massive');
6
legend boxoff;
grid on
temp = 1;
t = 1;
equal = [];
for i = 1:7 % 7 plots membership functions
temp1 = E1(:,i);
for j = 1:7 % 7 plots membership functions i.e. for all possible combinations
temp2 = E1(:,j);
if temp1==temp2
% fprintf('Fuzzy set %s and %s is equal. \n \n',E2{i,1},E2{j,1});
equal(temp,1) = i;
equal(temp,2) = j;
equal(temp,3) = 1;
EQ(t,1) = i;EQ(t,2) = j;t = t+1;
else
% fprintf('Fuzzy set %s and %s is not equal. \n',E2{i,1},E2{j,1});
equal(temp,1) = i;
equal(temp,2) = j;
equal(temp,3) = 0;
end
temp = temp + 1;
end
7
end
clear i j;
8
9
10
11
12
Problem 2: Part (b)
% A membership function A contains another membership function B or B is subset of A if and
only if
% the membership values of B is less than or equal to membership values of A.
temp = 1;
contain = [];
for i = 1:7 % no. of membership functions
for j = 1:7 % no. of membership functions i.e. for all possible combinations
if E1(:,i)<=E1(:,j)
% fprintf('Memebrship function %s is subset of %s. \n \n',E2{i,1},E2{j,1});
contain(temp,1) = i;
contain(temp,2) = j;
temp = temp+1;
else
% fprintf('Memebrship function %s is not a subset of %s. \n',E2{i,1},E2{j,1});
end
end
end
clear i j;
for i = 1:size(contain,1)
figure;
plot(W, [E1(:,contain(i,1)) E1(:,contain(i,2))]);
ylim([0 1]);
xlabel('Weight (in Kg)');
ylabel('Membership Grades');
title(sprintf('Problem 2: Plot of containment of membership functions %s and
%s',E2{contain(i,1),1},E2{contain(i,2),1}));
legend(E2{contain(i,1),1},E2{contain(i,2),1});
legend boxoff;
grid on
end
13
14
15
16
17
18
Problem 2: Part (c)
% complement of all membership functions.
figure;subplot(211);
plot(W,[VLight Light Normal Middle Heavy VHeavy Massive]);
ylim([0 1]);
xlabel('Weight (in Kg)');
ylabel('Membership Grades');
title('Problem 2: Plot of membership functions');
legend('Very Light','Light','Normal','Middle','Heavy','Very Heavy','Massive');
legend boxoff;
grid on
subplot(212);
plot(W,[Comp_MF(:,1) Comp_MF(:,2) Comp_MF(:,3) Comp_MF(:,4) Comp_MF(:,5) Comp_MF(:,6)
Comp_MF(:,7)]);
ylim([0 1]);
xlabel('Weight (in Kg)');
ylabel('Membership Grades');
title('Problem 2: Plot of complement membership functions');
legend('1 - Very Light','1 - Light','1 - Normal','1 - Middle','1 - Heavy','1 - Very Heavy','1
19
- Massive');
legend boxoff;
grid on
clear;
close all;
clc;
Problem 3:
Yes, Fuzzy Model of number system is a superset of crisp numbr system model.
Universe of discourse
U = {x | x belongs to Natural number, 1<=x<=10} i.e. all positive whole number from 1 to 10.
x = (1:1:10)';
20
set from a crisp can be derived with defining their belongingness. Fuzzy form of set A can be defined
as: Ex: Fuzz_A = {(1,0.2),(2,0.4),(3,1.0),(4,0.7),(5,0.4)}.
21
stem(x,Comp_Fuzz_A);
ylim([0 1]);
title('Complement of Fuzzy Set A');
xlabel('x');
ylabel('Membership grades');
legend('Complement of Fuzzy set A');
legend boxoff;
22
23
24
Yes the difference exists between the intersections for crisp and fuzzy
domain.
The intersection for crisp domain results null set. The intersection for fuzzy domain does not result
null set. Reason: This reason is due to the belongingness value i.e. membership grades. For crisp set,
the belongingness is either 0 or 1 then min(0,1) will always be 0. But in case of fuzzy set,
belongingness can be in between 0 and 1 or 0 or 1. Ex: min(0.5,0.3) = 0.3, which is non-zero value.
Justification:
A crisp set can be written with its belongingness value 0 or 1, Fuzzy set can have the value of
belongingness 0 or 1 or in between 0 and 1. The range of belongingness is always [0,1]. Hence, Fuzzy
set model of number system is superset of crisp model. Example 1: A = {1,2,3,4,5}; its fuzzy model
can be written as: Fuzz_A =
{(1,1.0),(2,1.0),(3,1.0),(4,1.0),(5,1.0),(6,0.0),(7,0.0),(8,0.0),(9,0.0),(10,0.0)}; Fuzz_A = A; Example 2: B =
{1,2,3,4,5}; its fuzzy model can be written as: Fuzzy_B = {(1,0.2),(2,0.4),(3,0.7),(4,0.6),(5,0.4)};
Fuzzy_B ~= B;
clear;
close all;
clc;
25
Problem 4:
% In order for a function (Let say 'f') to be qualified as a complement, it should
% satisfy at least the following two requirements:
Graphical representation:
% Let us take an example:
x = (0:0.1:10)';
ex = trimf(x, [2 5 7]);
% Axiom 1:
axiom1 = [];
temp = 1;
for i = 1:size(ex,1)
if ex(i,1)==0
if Comp_ex(i,1)==1
axiom1(temp,1) = x(i,1); % x axis point.
axiom1(temp,2) = ex(i,1); % y axis value.
% fprintf('Axiom 1: Part (a) f(0) = 1 for x = %d. \n',x(i,1));
else
fprintf('Axiom 1: Part (a) does not satisfied for x = %d. \n',x(i,1));
end
elseif ex(i,1)==1
if Comp_ex(i,1)==0
axiom1(temp,1) = x(i,1); % x axis point.
axiom1(temp,2) = ex(i,1); % y axis value.
% fprintf('Axiom 1: Part (b) f(1) = 0 for x = %d. \n',x(i,1));
else
fprintf('Axiom 1: Part (b) does not satisfied for x = %d. \n',x(i,1));
end
end
temp = temp+1;
end
clear temp i;
figure;
plot(x, [ex Comp_ex]);hold on
ylim([0 1]);
xlim([0 10]);
title('Problem 4: Example - Fuzzy Complement Operator');
xlabel('x');
ylabel('Membership grades');
26
legend('trimf(2,5,7)','1 - trimf(2,5,7)');
legend boxoff;
figure;
stem(axiom1(:,1), axiom1(:,2));
ylim([0 1]);
xlim([0 10]);
title('Problem 4: Example - Fuzzy Complement Operator - Axiom 1');
xlabel('x');
ylabel('Membership grades');
legend('Axiom 1');
legend boxoff;
% Axiom 2:
temp = 1;
axiom2 = [];
a = trimf(x, [2 5 7]);
Comp_a = 1 - a;
b = trimf(x, [3 6 9]);
Comp_b = 1 - b;
for i = 1:size(a,1)
if a(i,1)<b(i,1)
if Comp_a(i,1)>Comp_b(i,1) % non-increasing condition.
% fprintf('Axiom 2 has been satisfied for a = %d and b = %d. \n',a(i,1),b(i,1));
axiom2(temp,1) = x(i,1); % x axis point.
axiom2(temp,2) = a(i,1); % y axis value.
axiom2(temp,3) = b(i,1); % y axis value.
else
fprintf('Axiom 2 has not been satisfied for a = %d and b = %d.
\n',a(i,1),b(i,1));
end
end
temp = temp+1;
end
clear temp i;
figure;
plot(x,[a Comp_a b Comp_b]);
ylim([0 1]);
xlim([0 10]);
title('Problem 4: Membership function A and B with their complements');
xlabel('x');
ylabel('Membership grades');
legend('A','1 - A','B','1 - B');
legend boxoff;
figure;
stem(axiom2(:,1), axiom2(:,2:3));
ylim([0 1]);
xlim([0 10]);
title('Problem 4: Axiom 2');
xlabel('x');
ylabel('Membership grades');
legend('A for Axiom 2','B for Axiom 2');
legend boxoff;
27
28
29
Assignment 4: Dated - 05/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
Problem 5:
% In order for a function (Let say 'f') to be qualified as a complement, it should
% satisfy at least the following two requirements:
Graphical representation:
% Let us take an example:
x = (0:0.1:10)';
ex = trimf(x, [2 5 7]);
ss_label{1,1} = 'Example MF (A)';
% Axiom 1:
axiom1 = [];
temp = 1;
for i = 1:size(ex,1)
if ex(i,1)==0
if Comp_ex(i,1)==1
axiom1(temp,1) = x(i,1); % x axis point.
axiom1(temp,2) = ex(i,1); % y axis value.
30
% fprintf('Axiom 1: Part (a) f(0) = 1 for x = %d. \n',x(i,1));
else
fprintf('Axiom 1: Part (a) does not satisfied for x = %d. \n',x(i,1));
end
elseif ex(i,1)==1
if Comp_ex(i,1)==0
axiom1(temp,1) = x(i,1); % x axis point.
axiom1(temp,2) = ex(i,1); % y axis value.
% fprintf('Axiom 1: Part (b) f(1) = 0 for x = %d. \n',x(i,1));
else
fprintf('Axiom 1: Part (b) does not satisfied for x = %d. \n',x(i,1));
end
end
temp = temp+1;
end
clear temp i;
figure;
stem(axiom1(:,1), axiom1(:,2));
ylim([0 1]);
xlim([0 10]);
title('Problem 5: Example - Sugeno Class Fuzzy Complement Operator - Axiom 1');
xlabel('x');
ylabel('Membership grades');
legend('Axiom 1');
legend boxoff;
% Axiom 2:
temp = 1;
axiom2 = [];
lambda = 2;
a = trimf(x, [2 5 7]);
Comp_a = (1 - a)./(a + (lambda).*a);
b = trimf(x, [3 6 9]);
Comp_b = (1 - b)./(b + (lambda).*b);
for i = 1:size(a,1)
if a(i,1)<b(i,1)
if Comp_a(i,1)>Comp_b(i,1) % non-increasing condition.
% fprintf('Axiom 2 has been satisfied for a = %d and b = %d. \n',a(i,1),b(i,1));
axiom2(temp,1) = x(i,1); % x axis point.
axiom2(temp,2) = a(i,1); % y axis value.
axiom2(temp,3) = b(i,1); % y axis value.
else
fprintf('Axiom 2 has not been satisfied for a = %d and b = %d.
\n',a(i,1),b(i,1));
end
end
temp = temp+1;
end
clear temp i;
figure;
plot(x,[a Comp_a b Comp_b]);
ylim([0 1]);
xlim([0 10]);
31
title('Problem 5: Membership function A and B with their complements');
xlabel('x');
ylabel('Membership grades');
legend('A','1 - A','B','1 - B');
legend boxoff;
figure;
stem(axiom2(:,1), axiom2(:,2:3));
ylim([0 1]);
xlim([0 10]);
title('Problem 5: Axiom 2');
xlabel('x');
ylabel('Membership grades');
legend('A for Axiom 2','B for Axiom 2');
legend boxoff;
32
Axiom 1: Part (a) does not satisfied for x = 9.
Axiom 1: Part (a) does not satisfied for x = 9.100000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.200000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.300000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.400000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.500000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.600000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.700000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.800000e+00.
Axiom 1: Part (a) does not satisfied for x = 9.900000e+00.
Axiom 1: Part (a) does not satisfied for x = 10.
33
34
Assignment 4: Dated - 05/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
Problem 6:
% In order for a function (Let say 'f') to be qualified as a complement, it should
% satisfy at least the following two requirements:
35
Graphical representation:
% Let us take an example:
x = (0:0.1:10)';
ex = trimf(x, [2 5 7]);
yy_label{1,1} = 'Example MF (A)';
% Axiom 1:
axiom1 = [];
temp = 1;
for i = 1:size(ex,1)
if ex(i,1)==0
if Comp_ex(i,1)==1
axiom1(temp,1) = x(i,1); % x axis point.
axiom1(temp,2) = ex(i,1); % y axis value.
% fprintf('Axiom 1: Part (a) f(0) = 1 for x = %d. \n',x(i,1));
else
fprintf('Axiom 1: Part (a) does not satisfied for x = %d. \n',x(i,1));
end
elseif ex(i,1)==1
if Comp_ex(i,1)==0
axiom1(temp,1) = x(i,1); % x axis point.
axiom1(temp,2) = ex(i,1); % y axis value.
% fprintf('Axiom 1: Part (b) f(1) = 0 for x = %d. \n',x(i,1));
else
fprintf('Axiom 1: Part (b) does not satisfied for x = %d. \n',x(i,1));
end
end
temp = temp+1;
end
clear temp i;
figure;
stem(axiom1(:,1), axiom1(:,2));
ylim([0 1]);
xlim([0 10]);
title('Problem 6: Example - Yager Class Fuzzy Complement Operator - Axiom 1');
xlabel('x');
ylabel('Membership grades');
legend('Axiom 1');
legend boxoff;
36
% Axiom 2:
temp = 1;
axiom2 = [];
w = 2;
a = trimf(x, [2 5 7]);
Comp_a = (1 - a.^w).^(1/w);
b = trimf(x, [3 6 9]);
Comp_b = (1 - b.^w).^(1/w);
for i = 1:size(a,1)
if a(i,1)<b(i,1)
if Comp_a(i,1)>Comp_b(i,1) % non-increasing condition.
% fprintf('Axiom 2 has been satisfied for a = %d and b = %d. \n',a(i,1),b(i,1));
axiom2(temp,1) = x(i,1); % x axis point.
axiom2(temp,2) = a(i,1); % y axis value.
axiom2(temp,3) = b(i,1); % y axis value.
else
fprintf('Axiom 2 has not been satisfied for a = %d and b = %d.
\n',a(i,1),b(i,1));
end
end
temp = temp+1;
end
clear temp i;
figure;
plot(x,[a Comp_a b Comp_b]);
ylim([0 1]);
xlim([0 10]);
title('Problem 6: Membership function A and B with their complements');
xlabel('x');
ylabel('Membership grades');
legend('A','1 - A','B','1 - B');
legend boxoff;
figure;
stem(axiom2(:,1), axiom2(:,2:3));
ylim([0 1]);
xlim([0 10]);
title('Problem 6: Axiom 2');
xlabel('x');
ylabel('Membership grades');
legend('A for Axiom 2','B for Axiom 2');
legend boxoff;
37
38
39
Assignment 4: Dated - 04/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
Problem 7:
% Universe of discourse is:
% X = {x | x belongs to [0,10] }
x = (0:0.001:10)';
u1 = trimf(x,[0,3,7]);
part{1,1} = 'trimf(0,3,7)';
u2 = trapmf(x, [0,2,7,9]);
part{2,1} = 'trapmf(0,2,7,9)';
u3 = gaussmf(x, [2.5,7]);
part{3,1} = 'gaussmf(2,5,7)';
u4 = gbellmf(x, [3,7,9]);
part{4,1} = 'gbellmf(3,7,9)';
u5 = sigmf(x, [3,7]);
part{5,1} = 'sigmf(3,7)';
prob_part = inputdlg('How many parts are there for this problem 7?','No. of parts',1,{'5'});
prob_part = str2double(prob_part{1,1});
% Sugeno's Class
sug = [];
ss_label = [];
lambda = 0:1:10; % range of lambda is (-1, infinity).
40
for i = 1:size(lambda,2) % for different values of lambda
l = lambda(1,i);
s1 = 1 - u;
s2 = 1 + (l.*u);
sug(:,i) = s1./s2; % sugeno's class of complement
ss_label{1,i} = strcat('Lambda=',num2str(l));
end
figure;
plot(x,u);hold on
ylim([0 1]);
title(sprintf('Problem 7: Membership function Part (%s)',prob{1,1}));
xlabel('x');
ylabel('Memebrship grades');
legend(sprintf('(%s) %s',prob{1,1},part{pr,1}));
legend boxoff;
figure;
for i = 1:size(lambda,2) % for different values of lambda
plot(x,sug(:,i));hold on
ylim([0 1]);
end
title(sprintf('Problem 7: Part (%s) Sugeno Class of complement for different values of
lambda',prob{1,1}));
xlabel('x');
ylabel('Membership grades');
legend(ss_label);
legend boxoff;
% Yager's Class
yag = [];
yy_label = [];
w = 1:1:10; % range of w is (0, infinity).
for i = 1:size(w,2) % for different values of w
l = w(1,i);
w1 = 1 - (u.^l);
w2 = w1.^(1/l);
yag(:,i) = w2; % yager's class of complement
yy_label{1,i} = strcat('w=',num2str(l));
end
figure;
for i = 1:size(w,2) % for different values of w
plot(x,yag(:,i));hold on
ylim([0 1]);
end
title(sprintf('Problem 7: Part (%s) Yager Class of complement for different values of
w',prob{1,1}));
xlabel('x');
ylabel('Membership grades');
legend(yy_label);
legend boxoff;
clear i;
41
for i = 1:size(lambda,2) % for different values of lambda
plot(x,sug(:,i));hold on
ylim([0 1]);
end
for i = 1:size(w,2) % for different values of w
plot(x,yag(:,i));hold on
ylim([0 1]);
end
title(sprintf('Problem 7: Part (%s) Sugeno and Yager Class of complements',prob{1,1}));
xlabel('x');
ylabel('Membership grades');
tt_label = [ss_label yy_label];
legend(tt_label);
legend boxoff;
end
42
43
44
45
46
47
48
49
50
51
Assignment 4: Dated - 05/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
Problem 8:
% Universe of discourse is:
% X = {x | x belongs to [0,10] }
x = (0:0.001:10)';
u1 = trimf(x,[0,3,7]);
part{1,1} = 'trimf(0,3,7)';
u2 = trapmf(x, [0,2,7,9]);
part{2,1} = 'trapmf(0,2,7,9)';
u3 = gaussmf(x, [2.5,7]);
part{3,1} = 'gaussmf(2,5,7)';
u4 = gbellmf(x, [3,7,9]);
part{4,1} = 'gbellmf(3,7,9)';
u5 = sigmf(x, [3,7]);
part{5,1} = 'sigmf(3,7)';
52
Dombi's class of Fuzzy Union or S-norms.
for two membership functions a and b. Dombi_Snorm = 1./(1 + ( ( (1./a) - 1)^(-lambda) + ( (1./b) -
1)^(-lambda) )^( (-1)/lambda) ); % range of lamda is (0, infinity).
for j = 1:str2double(num_class{1,1})
lambda = 1:1:4;
alpha = 0:0.2:1;
w = 1:1:8;
Snorm = [];
Snorm1 = [];
Snorm2 = [];
Snorm3 = [];
a = u1;
b = u2;
c = u3;
d = u4;
e = u5;
Snorm_label = cell(1,1);
Comp_Snorm_label = cell(1,1);
Snorm_label{1,1} = 'a';
Snorm_label{1,2} = 'b';
Snorm_label{1,3} = 'c';
Snorm_label{1,4} = 'd';
Snorm_label{1,5} = 'e';
Comp_Snorm_label{1,1} = '1 - a';
Comp_Snorm_label{1,2} = '1 - b';
Comp_Snorm_label{1,3} = '1 - c';
Comp_Snorm_label{1,4} = '1 - d';
Comp_Snorm_label{1,5} = '1 - e';
if strcmp(class_snorm{1,1},'1')
class = 'Dombi';
for i = 1:size(lambda,2)
% between a and b.
Snorm1(:,i) = 1./(1 + ( ( (1./a) - 1).^(-(lambda(1,i))) + ( (1./b) - 1).^(-
(lambda(1,i))) ).^( (-1)/(lambda(1,i))) );
% between (a union b) and c.
53
Snorm2(:,i) = 1./(1 + ( ( (1./Snorm1(:,i)) - 1).^(-(lambda(1,i))) + ( (1./c) -
1).^(-(lambda(1,i))) ).^( (-1)/(lambda(1,i))) );
% between (a union b union c) and d.
Snorm3(:,i) = 1./(1 + ( ( (1./Snorm2(:,i)) - 1).^(-(lambda(1,i))) + ( (1./d) -
1).^(-(lambda(1,i))) ).^( (-1)/(lambda(1,i))) );
% between (a union b union c union d) and e.
Snorm(:,i) = 1./(1 + ( ( (1./Snorm3(:,i)) - 1).^(-(lambda(1,i))) + ( (1./e) -
1).^(-(lambda(1,i))) ).^( (-1)/(lambda(1,i))) );
% complement of s-norms.
Comp_Snorm(:,i) = 1 - Snorm(:,i);
Snorm_label{1,i+5} = strcat('Lambda=',num2str(lambda(1,i)));
Comp_Snorm_label{1,i+5} = strcat('Alpha=',num2str(alpha(1,i)));
end
elseif strcmp(class_snorm{1,1},'2')
class = 'Dubois-Prade';
for i = 1:size(alpha,2)
% between a and b.
temp1 = min(a, b);
temp2 = min(temp1, 1 - alpha(1,i));
temp3 = max(1 - a, 1 - b);
temp4 = max(temp3, alpha(1,i));
Snorm1(:,i) = ( a + b - a.*b - temp2 ) ./ ( temp4 );
% between (a union b) and c.
temp1 = min(Snorm1(:,i), c);
temp2 = min(temp1, 1 - alpha(1,i));
temp3 = max(1 - Snorm1(:,i), 1 - c);
temp4 = max(temp3, alpha(1,i));
Snorm2(:,i) = ( Snorm1(:,i) + c - Snorm1(:,i).*c - temp2 ) ./ ( temp4 );
% between (a union b union c) and d.
temp1 = min(Snorm2(:,i), d);
temp2 = min(temp1, 1 - alpha(1,i));
temp3 = max(1 - Snorm2(:,i), 1 - d);
temp4 = max(temp3, alpha(1,i));
Snorm3(:,i) = ( Snorm2(:,i) + d - Snorm2(:,i).*d - temp2 ) ./ ( temp4 );
% between (a union b union c union d) and e.
temp1 = min(Snorm3(:,i), e);
temp2 = min(temp1, 1 - alpha(1,i));
temp3 = max(1 - Snorm3(:,i), 1 - e);
temp4 = max(temp3, alpha(1,i));
Snorm(:,i) = ( Snorm3(:,i) + e - Snorm3(:,i).*e - temp2 ) ./ ( temp4 );
% complement of s-norms.
Comp_Snorm(:,i) = 1 - Snorm(:,i);
Snorm_label{1,i+5} = strcat('Alpha=',num2str(alpha(1,i)));
Comp_Snorm_label{1,i+5} = strcat('Alpha=',num2str(alpha(1,i)));
end
elseif strcmp(class_snorm{1,1},'3')
class = 'Yager';
for i = 1:size(w,2)
% between a and b.
Snorm1(:,i) = min( 1, ( a.^w(1,i) + b.^w(1,i) ).^( 1/w(1,i) ) );
% between (a union b) and c.
Snorm2(:,i) = min( 1, ( Snorm1(:,i).^w(1,i) + c.^w(1,i) ).^( 1/w(1,i) ) );
% between (a union b union c) and d.
Snorm3(:,i) = min( 1, ( Snorm2(:,i).^w(1,i) + d.^w(1,i) ).^( 1/w(1,i) ) );
% between (a union b union c union d) and e.
Snorm(:,i) = min( 1, ( Snorm3(:,i).^w(1,i) + e.^w(1,i) ).^( 1/w(1,i) ) );
% complement of s-norms.
54
Comp_Snorm(:,i) = 1 - Snorm(:,i);
Snorm_label{1,i+5} = strcat('w=',num2str(w(1,i)));
Comp_Snorm_label{1,i+5} = strcat('w=',num2str(w(1,i)));
end
end
end
55
56
57
Assignment 4: Dated - 05/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
Problem 9:
% Universe of discourse is:
% X = {x | x belongs to [0,10] }
x = (0:0.001:10)';
u1 = trimf(x,[0,3,7]);
part{1,1} = 'trimf(0,3,7)';
u2 = trapmf(x, [0,2,7,9]);
part{2,1} = 'trapmf(0,2,7,9)';
u3 = gaussmf(x, [2.5,7]);
part{3,1} = 'gaussmf(2,5,7)';
u4 = gbellmf(x, [3,7,9]);
part{4,1} = 'gbellmf(3,7,9)';
u5 = sigmf(x, [3,7]);
part{5,1} = 'sigmf(3,7)';
58
Dombi's class of T-norm.
for two membership functions a and b. Dombi_Tnorm = 1./(1 + ( ( (1./a) - 1)^(lambda) + ( (1./b) -
1)^(lambda) )^( 1/lambda) ); % range of lamda is (0, infinity).
for j = 1:str2double(num_class{1,1})
lambda = 1:1:4;
alpha = 0:0.2:1;
w = 1:1:8;
Tnorm = [];
Tnorm1 = [];
Tnorm2 = [];
Tnorm3 = [];
a = u1;
b = u2;
c = u3;
d = u4;
e = u5;
Tnorm_label = cell(1,1);
Comp_Tnorm_label = cell(1,1);
Tnorm_label{1,1} = 'a';
Tnorm_label{1,2} = 'b';
Tnorm_label{1,3} = 'c';
Tnorm_label{1,4} = 'd';
Tnorm_label{1,5} = 'e';
Comp_Tnorm_label{1,1} = '1 - a';
Comp_Tnorm_label{1,2} = '1 - b';
Comp_Tnorm_label{1,3} = '1 - c';
Comp_Tnorm_label{1,4} = '1 - d';
Comp_Tnorm_label{1,5} = '1 - e';
if strcmp(class_tnorm{1,1},'1')
class = 'Dombi';
for i = 1:size(lambda,2)
% between a and b.
Tnorm1(:,i) = 1./(1 + ( ( (1./a) - 1).^((lambda(1,i))) + ( (1./b) -
1).^((lambda(1,i))) ).^( (1)/(lambda(1,i))) );
% between (a union b) and c.
59
Tnorm2(:,i) = 1./(1 + ( ( (1./Tnorm1(:,i)) - 1).^((lambda(1,i))) + ( (1./c) -
1).^((lambda(1,i))) ).^( (1)/(lambda(1,i))) );
% between (a union b union c) and d.
Tnorm3(:,i) = 1./(1 + ( ( (1./Tnorm2(:,i)) - 1).^((lambda(1,i))) + ( (1./d) -
1).^((lambda(1,i))) ).^( (1)/(lambda(1,i))) );
% between (a union b union c union d) and e.
Tnorm(:,i) = 1./(1 + ( ( (1./Tnorm3(:,i)) - 1).^((lambda(1,i))) + ( (1./e) -
1).^((lambda(1,i))) ).^( (1)/(lambda(1,i))) );
% complement of s-norms.
Comp_Tnorm(:,i) = 1 - Tnorm(:,i);
Tnorm_label{1,i+5} = strcat('Lambda=',num2str(lambda(1,i)));
Comp_Tnorm_label{1,i+5} = strcat('Alpha=',num2str(alpha(1,i)));
end
elseif strcmp(class_tnorm{1,1},'2')
class = 'Dubois-Prade';
for i = 1:size(alpha,2)
% between a and b.
temp1 = max(a, b);
temp2 = max(temp1, alpha(1,i));
Tnorm1(:,i) = ( a.*b ) ./ ( temp2 );
% between (a union b) and c.
temp1 = max(Tnorm1(:,i), c);
temp2 = max(temp1, alpha(1,i));
Tnorm2(:,i) = ( Tnorm1(:,i).*c ) ./ ( temp2 );
% between (a union b union c) and d.
temp1 = max(Tnorm2(:,i), d);
temp2 = max(temp1, alpha(1,i));
Tnorm3(:,i) = ( Tnorm2(:,i).*d ) ./ ( temp2 );
% between (a union b union c union d) and e.
temp1 = max(Tnorm3(:,i), e);
temp2 = max(temp1, alpha(1,i));
Tnorm(:,i) = ( Tnorm3(:,i).*e ) ./ ( temp2 );
% complement of s-norms.
Comp_Tnorm(:,i) = 1 - Tnorm(:,i);
Tnorm_label{1,i+5} = strcat('Alpha=',num2str(alpha(1,i)));
Comp_Tnorm_label{1,i+5} = strcat('Alpha=',num2str(alpha(1,i)));
end
elseif strcmp(class_tnorm{1,1},'3')
class = 'Yager';
for i = 1:size(w,2)
% between a and b.
Tnorm1(:,i) = 1 - min( 1, ( (1- a).^w(1,i) + (1 - b).^w(1,i) ).^( 1/w(1,i) ) );
% between (a union b) and c.
Tnorm2(:,i) = 1 - min( 1, ( (1 - Tnorm1(:,i)).^w(1,i) + (1 - c).^w(1,i) ).^(
1/w(1,i) ) );
% between (a union b union c) and d.
Tnorm3(:,i) = 1 - min( 1, ( (1 - Tnorm2(:,i)).^w(1,i) + (1 - d).^w(1,i) ).^(
1/w(1,i) ) );
% between (a union b union c union d) and e.
Tnorm(:,i) = 1 - min( 1, ( (1 - Tnorm3(:,i)).^w(1,i) + (1 - e).^w(1,i) ).^(
1/w(1,i) ) );
% complement of s-norms.
Comp_Tnorm(:,i) = 1 - Tnorm(:,i);
Tnorm_label{1,i+5} = strcat('w=',num2str(w(1,i)));
Comp_Tnorm_label{1,i+5} = strcat('w=',num2str(w(1,i)));
end
end
60
% plot for all Snorms.
figure;
plot(x,[a b c d e]);hold on
plot(x,Tnorm(:,:));hold on
ylim([0 1]);
xlabel('x');
title(sprintf('%s class of Fuzzy Intersection or T-Norms',class));
ylabel('Memebrship grades');
legend(Tnorm_label);
legend boxoff;
end
61
62
63
Assignment 4: Dated - 05/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
Problem 10:
% Universe of discourse is:
% X = {x | x belongs to [0,10] }
x = (0:0.001:10)';
u1 = trimf(x,[1,4.5,8.6]);
part{1,1} = 'trimf(1,4.5,8.6)';
u2 = trapmf(x, [0.5,3.2,6.4,9.8]);
part{2,1} = 'trapmf(0.5,3.2,6.4,9.8)';
u3 = gaussmf(x, [2,6]);
part{3,1} = 'gaussmf(2,6)';
u4 = gbellmf(x, [3.5,7,9.5]);
part{4,1} = 'gbellmf(3.5,7,9.5)';
u5 = sigmf(x, [2.3,8]);
part{5,1} = 'sigmf(2.3,8)';
64
Einstein sum s-norm.
for two membership functions a and b. Ses = (a + b)./(1 + a.*b);
a = u1;
b = u2;
c = u3;
d = u4;
e = u5;
snorm_label = cell(1,1);
snorm_label{1,1} = 'a';
snorm_label{1,2} = 'b';
snorm_label{1,3} = 'c';
snorm_label{1,4} = 'd';
snorm_label{1,5} = 'e';
Comp_snorm_label = cell(1,1);
Comp_snorm_label{1,1} = '1 - a';
Comp_snorm_label{1,2} = '1 - b';
Comp_snorm_label{1,3} = '1 - c';
Comp_snorm_label{1,4} = '1 - d';
Comp_snorm_label{1,5} = '1 - e';
for j = 1:str2double(num_class{1,1})
if strcmp(class_snorm{1,1},'1')
class = 'Drastic Sum S-norm';
for k = 1:size(a,1)
% between a and b.
if b(k,1)==0
Sds1(k,1) = a(k,1);
elseif a(k,1)==0;
Sds1(k,1) = b(k,1);
else
Sds1(k,1) = 1;
end
end
for k = 1:size(a,1)
% between (a b) and c.
if c(k,1)==0
Sds2(k,1) = Sds1(k,1);
65
elseif Sds1(k,1)==0;
Sds2(k,1) = c(k,1);
else
Sds2(k,1) = 1;
end
end
for k = 1:size(a,1)
% between (a b c) and d.
if d(k,1)==0
Sds3(k,1) = Sds2(k,1);
elseif Sds2(k,1)==0;
Sds3(k,1) = d(k,1);
else
Sds3(k,1) = 1;
end
end
for k = 1:size(a,1)
% between (a b c d) and e.
if e(k,1)==0
Sds(k,1) = Sds3(k,1);
elseif Sds3(k,1)==0;
Sds(k,1) = e(k,1);
else
Sds(k,1) = 1;
end
end
snorm = Sds;
snorm_label{1,6} = 'Drastic Sum S-norm';
% complement of s-norms.
Comp_Sds = 1 - Sds;
Comp_Snorm = Comp_Sds;
Comp_snorm_label{1,6} = '1 - (Drastic Sum S-norm)';
elseif strcmp(class_snorm{1,1},'2')
class = 'Einstein Sum S-norm';
% between a and b.
Ses1 = (a + b)./(1 + a.*b);
% between (a b) and c.
Ses2 = (Ses1 + c)./(1 + Ses1.*c);
% between (a b c) and d.
Ses3 = (Ses2 + d)./(1 + Ses2.*d);
% between (a b c d) and e.
Ses = (Ses3 + e)./(1 + Ses3.*e);
snorm = Ses;
snorm_label{1,6} = 'Einstein Sum S-norm';
% complement of s-norms.
Comp_Ses = 1 - Ses;
Comp_Snorm = Comp_Ses;
Comp_snorm_label{1,6} = '1 - (Einstein Sum S-norm)';
elseif strcmp(class_snorm{1,1},'3')
class = 'Algebric Sum S-norm';
% between a and b.
Sas1 = a + b - a.*b;
% between (a b) and c.
Sas2 = Sas1 + c - Sas1.*c;
66
% between (a b c) and d.
Sas3 = Sas2 + d - Sas2.*d;
% between (a b c d) and e.
Sas = Sas3 + e - Sas3.*e;
snorm = Sas;
snorm_label{1,6} = 'Algebric Sum S-norm';
% complement of s-norms.
Comp_Sas = 1 - Sas;
Comp_Snorm = Comp_Sas;
Comp_snorm_label{1,6} = '1 - (Algebric Sum S-norm)';
elseif strcmp(class_snorm{1,1},'4')
class = 'Maximum/Basic Sum S-norm';
% between a and b.
Smax1 = max(a, b);
% between (a b) and c.
Smax2 = max(Smax1, c);
% between (a b c) and d.
Smax3 = max(Smax2, d);
% between (a b c d) and e.
Smax = max(Smax3, e);
snorm = Smax;
snorm_label{1,6} = 'Maximum/Basic Sum S-norm';
% complement of s-norms.
Comp_Smax = 1 - Smax;
Comp_Snorm = Comp_Smax;
Comp_snorm_label{1,6} = '1 - (Maximum/Basic Sum S-norm)';
end
end
67
68
69
70
71
Assignment 4: Dated - 05/02/2017.
Mohd. Aqib (16204272)
clear;
close all;
clc;
Problem 11:
% Universe of discourse is:
% X = {x | x belongs to [0,10] }
x = (0:0.001:10)';
u1 = trimf(x,[1,4.5,8.6]);
part{1,1} = 'trimf(1,4.5,8.6)';
u2 = trapmf(x, [0.5,3.2,6.4,9.8]);
part{2,1} = 'trapmf(0.5,3.2,6.4,9.8)';
u3 = gaussmf(x, [2,6]);
part{3,1} = 'gaussmf(2,6)';
u4 = gbellmf(x, [3.5,7,9.5]);
part{4,1} = 'gbellmf(3.5,7,9.5)';
u5 = sigmf(x, [2.3,8]);
part{5,1} = 'sigmf(2.3,8)';
a = u1;
b = u2;
c = u3;
d = u4;
e = u5;
tnorm_label = cell(1,1);
tnorm_label{1,1} = 'a';
tnorm_label{1,2} = 'b';
tnorm_label{1,3} = 'c';
tnorm_label{1,4} = 'd';
tnorm_label{1,5} = 'e';
Comp_tnorm_label = cell(1,1);
72
Comp_tnorm_label{1,1} = '1 - a';
Comp_tnorm_label{1,2} = '1 - b';
Comp_tnorm_label{1,3} = '1 - c';
Comp_tnorm_label{1,4} = '1 - d';
Comp_tnorm_label{1,5} = '1 - e';
for j = 1:str2double(num_class{1,1})
if strcmp(class_tnorm{1,1},'1')
class = 'Drastic Product t-norm';
for k = 1:size(a,1)
% between a and b.
if b(k,1)==0
tds1(k,1) = a(k,1);
elseif a(k,1)==0;
tds1(k,1) = b(k,1);
else
tds1(k,1) = 1;
end
end
for k = 1:size(a,1)
% between (a b) and c.
if c(k,1)==0
tds2(k,1) = tds1(k,1);
elseif tds1(k,1)==0;
tds2(k,1) = c(k,1);
else
tds2(k,1) = 1;
end
end
for k = 1:size(a,1)
% between (a b c) and d.
if d(k,1)==0
tds3(k,1) = tds2(k,1);
elseif tds2(k,1)==0;
tds3(k,1) = d(k,1);
else
tds3(k,1) = 1;
end
end
for k = 1:size(a,1)
% between (a b c d) and e.
if e(k,1)==0
tds(k,1) = tds3(k,1);
elseif tds3(k,1)==0;
tds(k,1) = e(k,1);
else
tds(k,1) = 1;
end
end
tnorm = tds;
73
tnorm_label{1,6} = class;
% complement of s-norms.
Comp_tds = 1 - tds;
Comp_tnorm = Comp_tds;
Comp_tnorm_label{1,6} = strcat('1-',class);
elseif strcmp(class_tnorm{1,1},'2')
class = 'Einstein Product T-norm';
% between a and b.
tes1 = (a.*b)./(2 - (a + b - a.*b));
% between (a b) and c.
tes2 = (tes1.*c)./(2 - (tes1 + c - tes1.*c));
% between (a b c) and d.
tes3 = (tes2.*d)./(2 - (tes2 + c - tes2.*c));
% between (a b c d) and e.
tes = (tes3.*e)./(2 - (tes3 + e - tes3.*e));
tnorm = tes;
tnorm_label{1,6} = class;
% complement of s-norms.
Comp_tes = 1 - tes;
Comp_tnorm = Comp_tes;
Comp_tnorm_label{1,6} = strcat('1-',class);
elseif strcmp(class_tnorm{1,1},'3')
class = 'Algebric Product T-norm';
% between a and b.
tas1 = a.*b;
% between (a b) and c.
tas2 = tas1.*c;
% between (a b c) and d.
tas3 = tas2.*d;
% between (a b c d) and e.
tas = tas3.*e;
tnorm = tas;
tnorm_label{1,6} = class;
% complement of s-norms.
Comp_tas = 1 - tas;
Comp_tnorm = Comp_tas;
Comp_tnorm_label{1,6} = strcat('1-',class);
elseif strcmp(class_tnorm{1,1},'4')
class = 'Maximum/Basic Product T-norm';
% between a and b.
tmax1 = min(a, b);
% between (a b) and c.
tmax2 = min(tmax1, c);
% between (a b c) and d.
tmax3 = min(tmax2, d);
% between (a b c d) and e.
tmax = min(tmax3, e);
tnorm = tmax;
tnorm_label{1,6} = class;
% complement of s-norms.
Comp_tmax = 1 - tmax;
Comp_tnorm = Comp_tmax;
Comp_tnorm_label{1,6} = strcat('1-',class);
end
74
plot(x,[a b c d e]);hold on
plot(x, tnorm);hold on
ylim([0 1]);
xlabel('x');
title(sprintf('Plot for %s',class));
ylabel('Memebrship grades');
legend(tnorm_label);
legend boxoff;
end
75
76
77
78
Published with MATLAB® R2015a
79