You are on page 1of 79

Assignment 4: Dated - 03/02/2017.

Mohd. Aqib (16204272)

clear;
close all;
clc;

Problem 1: For following fuzzy sets,


A = 0.7/2 + 0.3/3 + 0.9/4 + 1/5

B = 0.2/1 + 0.4/2 + 0.1/3

% 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;

% Problem 1: Part (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(P1);
ylim([0 1]);
xlabel('x');
ylabel('Membership grades');
title('Problem 1: min(A,B)');
legend('min(A,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)');

% Problem 1: Part (c)


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');

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');

% Problem 1: Part (d)

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;

Problem 2: W = {w | w belongs to [10,200] }


% Universe of discourse is:
W = 10:5:200;
W = W';

% 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

Problem 2: Part (a)


% If membership values of two fuzzy sets are equal then only we can say
% that membership functions are equal.

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;

% Plots for equal fuzzy sets.

for i = 1:size(EQ,1) % no. of equal pairs


% fprintf('Fuzzy set %s and %s is equal. \n',E2{EQ(i,1),1},E2{EQ(i,2),1});
figure;
plot(W,[E1(:,EQ(i,1)) E1(:,EQ(i,2))]);
ylim([0 1]);
xlabel('Weight (in Kg)');
ylabel('Membership Grades');
title(sprintf('Problem 2: Plot of membership functions for %s and
%s',E2{EQ(i,1),1},E2{EQ(i,2),1}));
legend(E2{EQ(i,1),1},E2{EQ(i,2),1});
legend boxoff;
grid on
end

clear equal EQ temp temp1 temp2 t 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;

% plots for containment of fuzzy sets.

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.

for i = 1:7 % no. of membership functions


Comp_MF(:,i) = 1 - E1(:,i); % complement
end

% plot for each membership function

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

% plot for complement of each membership function

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

Assignment 4: Dated - 05/02/2017.


Mohd. Aqib (16204272)

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)';

Given crisp set is:


A = {1,2,3,4,5} where, A is subset of Universe of discourse. In Crisp set, the belongingness would be
wither 1 or 0 for each number of the set. Crisp set is also a Fuzzy set with belongingness value 1.0 for
each number in the set. Crisp set can be written is: A = {(1,1.0),(2,1.0),(3,1.0),(4,1.0),(5,1.0)}; Fuzzy

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)}.

A = [1 1 1 1 1 0 0 0 0 0]; % crisp set A.

Fuzz_A = [0.2 0.4 1.0 0.7 0.4 0 0 0 0 0]; % fuzzy form of A.

% plot of Crisp set A.


figure;
stem(x,A);
ylim([0 1]);
title('Crisp Set A');
xlabel('x');
ylabel('Membership grades');
legend('Crisp set A');
legend boxoff;

% Complement of Crisp set A.


Comp_A = 1 - A;

% plot of Complement of Crisp set A.


figure;
stem(x,Comp_A);
ylim([0 1]);
title('Complement of Crisp Set A');
xlabel('x');
ylabel('Membership grades');
legend('Complement of Crisp set A');
legend boxoff;

% A intersection A' in Crisp domain.


A_min_Comp_A = min(A, Comp_A);
figure;
stem(x,A_min_Comp_A);
ylim([0 1]);
title('Intersection b/w A and Complement of A in Crisp Domain');
xlabel('x');
ylabel('Membership grades');
legend('min(A,1 - A) in crisp domain');
legend boxoff;

% plot of Fuzzy set A.


figure;
stem(x,Fuzz_A);
ylim([0 1]);
title('Fuzzy Set A');
xlabel('x');
ylabel('Membership grades');
legend('Fuzzy set A');
legend boxoff;

% Complement of Fuzzy set A.


Comp_Fuzz_A = 1 - Fuzz_A;

% plot of Complement of Fuzzy set A.


figure;

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;

% A intersection A' in Fuzzy domain.


Fuzz_A_min_Comp_A = min(Fuzz_A, Comp_Fuzz_A);
figure;
stem(x,Fuzz_A_min_Comp_A);
ylim([0 1]);
title('Intersection b/w A and Complement of A in Fuzzy Domain');
xlabel('x');
ylabel('Membership grades');
legend('min(A,1 - A) in fuzzy domain');
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;

Assignment 4: Dated - 05/02/2017.


Mohd. Aqib (16204272)

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:

Axiom 1: Boundary Condition


f(0) = 1 and f(1) = 0

Axiom 2: Non-Increasing condition


For all (a,b) belongs to [0,1], if (a<b) the f(a)>f(b) where, a and b denotes the membership values of
some fuzzy set.

Graphical representation:
% Let us take an example:
x = (0:0.1:10)';
ex = trimf(x, [2 5 7]);

% Its Complement would be:


Comp_ex = 1 - ex;

% 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:

Axiom 1: Boundary Condition


f(0) = 1 and f(1) = 0

Axiom 2: Non-Increasing condition


For all (a,b) belongs to [0,1], if (a<b) the f(a)>f(b) where, a and b denotes the membership values of
some fuzzy set.

Sugeno's Class of Complement.


C(a) = (1 - a)./(a + lambda.*a);

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)';

% Its Complement would be:


Comp_ex = [];
lambda = 2;
Comp_ex = (1 - ex)./(ex + (lambda).*ex);
ss_label{1,2} = strcat('Lambda=',num2str(lambda));
figure;
plot(x, [ex Comp_ex]);
ylim([0 1]);
xlim([0 10]);
title('Problem 5: Example - Sugeno Class Fuzzy Complement Operator');
xlabel('x');
ylabel('Membership grades');
legend(ss_label);
legend boxoff;

% 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;

Axiom 1: Part (a) does not satisfied for x = 0.


Axiom 1: Part (a) does not satisfied for x = 1.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 2.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 3.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 4.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 5.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 6.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 7.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 8.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 9.000000e-01.
Axiom 1: Part (a) does not satisfied for x = 1.
Axiom 1: Part (a) does not satisfied for x = 1.100000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.200000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.300000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.400000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.500000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.600000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.700000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.800000e+00.
Axiom 1: Part (a) does not satisfied for x = 1.900000e+00.
Axiom 1: Part (a) does not satisfied for x = 2.
Axiom 1: Part (a) does not satisfied for x = 7.
Axiom 1: Part (a) does not satisfied for x = 7.100000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.200000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.300000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.400000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.500000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.600000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.700000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.800000e+00.
Axiom 1: Part (a) does not satisfied for x = 7.900000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.
Axiom 1: Part (a) does not satisfied for x = 8.100000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.200000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.300000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.400000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.500000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.600000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.700000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.800000e+00.
Axiom 1: Part (a) does not satisfied for x = 8.900000e+00.

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:

Axiom 1: Boundary Condition


f(0) = 1 and f(1) = 0

Axiom 2: Non-Increasing condition


For all (a,b) belongs to [0,1], if (a<b) the f(a)>f(b) where, a and b denotes the membership values of
some fuzzy set.

Yager's Class of Complement.


C(a) = (1 - a.^w).^(1/w);

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)';

% Its Complement would be:


Comp_ex = [];
w = 2;
Comp_ex = (1 - ex.^w).^(1/w);
yy_label{1,2} = strcat('w=',num2str(w));
figure;
plot(x, [ex Comp_ex]);
ylim([0 1]);
xlim([0 10]);
title('Problem 6: Example - Yager Class Fuzzy Complement Operator');
xlabel('x');
ylabel('Membership grades');
legend(yy_label);
legend boxoff;

% 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 and Yager's class of complement.


for pr = 1:prob_part

prob = inputdlg('Which part of this for problem 7?','Problem part no.',1,{'a'});


if strcmp(prob{1,1},'a')
part_num = 1;
u = u1;
elseif strcmp(prob{1,1},'b')
part_num = 2;
u = u2;
elseif strcmp(prob{1,1},'c')
part_num = 3;
u = u3;
elseif strcmp(prob{1,1},'d')
part_num = 4;
u = u4;
elseif strcmp(prob{1,1},'e')
part_num = 5;
u = u5;
end

% 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;

% Combined plot of sugeno's and yager's class of complement.


figure;

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).

Dubois-Prade's class of Fuzzy Union or S-norms.


for two membership functions a and b. DuboisPrade_Snorm = ( a + b - a.*b - min(a, b, (1 - alpha) ) ) ./
( max( (1 - a), (1 - b), alpha ) ); % range of alpha is [0, 1].

Yager's class of Fuzzy Union or S-norms.


for two membership functions a and b. Yager_Snorm = min( 1, (a^w + b^w)^(1/w) ); % range of w is
(0, infinity).

num_class = inputdlg('How many class of S-norms you want to calculate?','No. of S-


norms',1,{'3'});

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 = [];

class_snorm = inputdlg('Which Class of S-norm you want to calculate?','S-norm


class',1,{'1'});

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

% plot for all Snorms.


figure;
plot(x,[a b c d e]);hold on
plot(x,Snorm(:,:));hold on
ylim([0 1]);
xlabel('x');
title(sprintf('%s class of Fuzzy Unions or S-Norms',class));
ylabel('Memebrship grades');
legend(Snorm_label);
legend boxoff;

% plot for all complements of Snorms.


figure;
plot(x,[1-a 1-b 1-c 1-d 1-e]);hold on
plot(x,Comp_Snorm(:,:));hold on
ylim([0 1]);
xlabel('x');
title(sprintf('Complement of %s class of Fuzzy Unions or S-Norms',class));
ylabel('Memebrship grades');
legend(Comp_Snorm_label);
legend boxoff;

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).

Dubois-Prade's class of T-norm.


for two membership functions a and b. DuboisPrade_Tnorm = ( a + b - a.*b - min(a, b, (1 - alpha) ) ) ./
( max( (1 - a), (1 - b), alpha ) ); % range of alpha is [0, 1].

Yager's class of T-norm.


for two membership functions a and b. Yager_Tnorm = 1 - min( 1, ((1 - a)^w + (1-b)^w)^(1/w) ); %
range of w is (0, infinity).

num_class = inputdlg('How many class of T-norms you want to calculate?','No. of T-


norms',1,{'3'});

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 = [];

class_tnorm = inputdlg('Which Class of T-norm you want to calculate?','T-norm


class',1,{'1'});

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;

% plot for all complements of Snorms.


figure;
plot(x,[1-a 1-b 1-c 1-d 1-e]);hold on
plot(x,Comp_Tnorm(:,:));hold on
ylim([0 1]);
xlabel('x');
title(sprintf('Complement of %s class of Fuzzy Intersection or T-Norms',class));
ylabel('Memebrship grades');
legend(Comp_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)';

Drastic sum s-norm.


for two membership functions a and b. if b==0 Sds = a; elseif a==0; Sds = b; else Sds = 1; end

64
Einstein sum s-norm.
for two membership functions a and b. Ses = (a + b)./(1 + a.*b);

Algebraic sum s-norm .


for two membership functions a and b. Sas = a + b - a.*b;

Maximum or basic s-norm


for two membership functions a and b. Smax = max(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';

num_class = inputdlg('How many class of s-norms you want to calculate?','No. of S-


norms',1,{'4'});

for j = 1:str2double(num_class{1,1})

class_snorm = inputdlg('Which Class of s-norm you want to calculate?','s-norm


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

% plot for all Snorms.


figure;
plot(x,[a b c d e]);hold on
plot(x, snorm);hold on
ylim([0 1]);
xlabel('x');
title(sprintf('Plot for %s',class));
ylabel('Memebrship grades');
legend(snorm_label);
legend boxoff;

% plot for all complements of Snorms.


figure;
plot(x,[1-a 1-b 1-c 1-d 1-e]);hold on
plot(x,Comp_Snorm);hold on
ylim([0 1]);
xlabel('x');
title(sprintf('Plot for Complement of %s',class));
ylabel('Memebrship grades');
legend(Comp_snorm_label);
legend boxoff;

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)';

Drastic product t-norm.


for two membership functions a and b. if b==1 tds = a; elseif a==1; tds = b; else tds = 0; end

Einstein product t -norm.


for two membership functions a and b. tes = a.*b./(2 - (a + b - a.*b));

Algebraic product t norm.


for two membership functions a and b. tas = a.*b;

Minimum or basic t-norm.


for two membership functions a and b. tmin = min(a, b);

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';

num_class = inputdlg('How many class of t-norms you want to calculate?','No. of T-


norms',1,{'4'});

for j = 1:str2double(num_class{1,1})

class_tnorm = inputdlg('Which Class of t-norm you want to calculate?','t-norm


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

% plot for all Snorms.


figure;

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;

% plot for all complements of Snorms.


figure;
plot(x,[1-a 1-b 1-c 1-d 1-e]);hold on
plot(x,Comp_tnorm);hold on
ylim([0 1]);
xlabel('x');
title(sprintf('Plot for Complement of %s',class));
ylabel('Memebrship grades');
legend(Comp_tnorm_label);
legend boxoff;

end

75
76
77
78
Published with MATLAB® R2015a

79

You might also like