KEMBAR78
Fuzzylogic Lab File | PDF | Fuzzy Logic | Function (Mathematics)
0% found this document useful (0 votes)
19 views23 pages

Fuzzylogic Lab File

The document outlines a series of experiments conducted using MATLAB to explore fuzzy logic and neural networks, specifically focusing on fuzzy sets, relations, and membership functions. Key experiments include obtaining union, intersection, and complement of fuzzy sets, finding fuzzy relations using max-min composition, and plotting triangular and Gaussian membership functions. The document serves as a practical guide for implementing fuzzy logic concepts through programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views23 pages

Fuzzylogic Lab File

The document outlines a series of experiments conducted using MATLAB to explore fuzzy logic and neural networks, specifically focusing on fuzzy sets, relations, and membership functions. Key experiments include obtaining union, intersection, and complement of fuzzy sets, finding fuzzy relations using max-min composition, and plotting triangular and Gaussian membership functions. The document serves as a practical guide for implementing fuzzy logic concepts through programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

DR.

AKHILESH DAS GUPTA


INSTITUTE OF PROFESSIONAL
STUDIES
Department of Electronics and Communication
Engineering

FUZZY LOGIC AND NEURAL NETWORKS


Paper Code: ECE-411T

SUBMITTED BY:
NIKHIL SRIVASTAVA

08815602821

ECE DEPARTMENT(F-5)
INDEX
S.N TITLE DATE SIGN
O
1. To obtain union, intersection, and
complement by MATLAB for
Fuzzy sets
2. Find the fuzzy relation using fuzzy max-
min method for the following Using
MATLAB program.

3. Using MATLAB programming to draw


triangular and Gaussian membership
function. Given x=0 to 10 with
increment of 0.1. Triangular
membership function is defined between
[5 6 7] and Gaussian membership is
defined between 2 and 4.

4. Using MATLAB program find the crisp


lambda cut set relation for lambda=0.6.

5. To study Speed control of motor by


using Fuzzy Logic Toolbox.

6. Write a program to construct and test


auto-associative network for input vector
using HEBB/Outer Product Rule.
EXPERIMENT NO. 1
Union, intersection, and complement of two Fuzzy sets by MATLAB.

1.1 Objective 1.2 Apparatus Required 1.3 Theory 1.4 Procedure 1.5 Result

1.1 OBJECTIVE:
. To obtain union, intersection, and complement by MATLAB for Fuzzy sets:
1 0.5 0.3 0.2
A={ + + + }
2 3 4 5

0.5 0.7 0.2 0.4


B={ + + + }
2 3 4 5

1.2 MACHINES & APPARATUS USED:

MATLAB installed Computer (Windows operating system)

1.3 THEORY

In the classical set, its characteristic function assigns a value of either 1 or 0 to each
individual in the universal set, there by discriminating between members and nonmembers of
the crisp set under consideration. The values assigned to

Fig 1.1

the elements of the universal set fall within a specified range and indicate the membership
grade of these elements in the set. Larger values denote higher degrees of set membership
such a function is called a membership function and the set is defined by it is a fuzzy set.

A fuzzy set is thus a set containing elements that have varying degrees of membership in the
set. This idea is in contrast with classical or crisp, set because members of a crisp set would
not be members unless their membership was full or complete, in that set (i.e., their
membership is assigned a value of 1). Elements in a fuzzy set, because their membership
need not be complete, can also be members of other fuzzy set on the same universe. Fuzzy set
are denoted by a set symbol with a tilde under strike. Fuzzy set is mapped to a real numbered
value in the interval 0 to 1. If an element of universe, say x, is a member of fuzzy set A then
the mapping is given by
μ A (x) € [0, 1]. This is the membership mapping and is shown in Fig.1.1

Considering Two fuzzy sets A ,B the universe X. For a given element x of the universe,
Venn diagram for Union and Intersection can be shown as:

Fig 1.2 Union of two fuzzy sets

Fig 1.3 Intersection of Fuzzy sets.

1.4 PROCEDURE:
Enter following code in M file and save the file.

PROGRAM:
% enter the two matrices
u=input(‘enter the first matrix’);
v=input(‘enter the second matrix’);

option=input(‘enter the option’);


%option 1 Union
%option 2 intersection
%option 3 complement
if (option==1)
w=max(u,v)
end
if (option==2)
p=min(u,v)
end
if (option==3)
option1=input(‘enter whether to find complement for first matrix
or second matrix’);
if (option1==1)
[m,n]=size(u);
q=ones(m)-u;
else
q=ones(m)-v;
end
end

On running the above code, following output will appear in command window.

OUTPUT:

(1) To find union of A and B


enter the first matrix[1 0.5 0.2 0.3]
enter the second matrix[0.5 0.7 0.2 0.4]
enter the option1
w=
1.0000 0.7000 0.2000 0.4000
(2) To find Intersection of A and B is
enter the first matrix[1 0.5 0.2 0.3]
enter the second matrix[0.5 0.7 0.2 0.4]
enter the option2
p=
0.5000 0.5000 0.2000 0.3000
(3) To find complement of A
enter the first matrix[1 0.5 0.2 0.3]
enter the second matrix[0.5 .7 .2 .4]
enter the option3
enter the whether to find complement for first matrix or second matrix
1
q=
0 0.5000

q=
0 0.5000 0.8000 0.7000

(4) To find complement of B


enter the first matrix[1 0.5 0.2 0.3]
enter the second matrix[0.5 .7 .2 .4]
enter the option3
enter the whether to find complement for first matrix or second matrix
2
q=
0.5000 0.3000 0.8000 0.6000

1.5 RESULT: Union, Intersection and Complement are obtained of fuzzy sets are
obtained.

EXPERIMENT NO. 2
FUZZY Relation by using Fuzzy Max min Composition in MATLAB.

2.1 Objective 2.2 Apparatus Required 2.3 Theory 2.4 Procedure 2.5 Result

2.1 OBJECTIVE:

Find the fuzzy relation using fuzzy max-min method for the following
Using MATLAB program

[ ]
0.2 0.3 0.4 [0.1 1
0.3 0.5 0.7 [0.4 [ ]0.2 ]
]0.7
S= [0.3
R=
1 0.8 0.6 ¿

2.2 MACHINES & APPARATUS USED:

MATLAB installed Computer (Windows operating system)

2.3 THEORY

Fuzzy relations also map elements of one universe, say X, to those of another universe, say

Y,
through the Cartesian product of the two universes. However, the ‘‘strength’’ of the relation
between ordered pairs of the two universes is not measured with the characteristic function,
but rather with a membership function expressing various ‘‘degrees’’ of strength of the
relation on the unit interval [0,1]. Hence, a fuzzy relation R is a mapping from the Cartesian
space X × Y to the interval [0,1], where the strength of the mapping is expressed by the
membership function of the relation for ordered pairs from the two universes, or μR(x, y).

Because fuzzy relations in general are fuzzy sets, we can define the Cartesian product to be
a relation between two or more fuzzy sets. Let A be a fuzzy set on universe X and B be a
fuzzy set on universe Y; then the Cartesian product between fuzzy sets A and B
will result in a fuzzy relation R , which is contained within the full Cartesian product space.

where the fuzzy relation has membership function μR(x, y) = μA×B (x, y) = min
(μA(x),μB(y))

Cartesian product is not the same operation as the arithmetic product. In the case of two-
dimensional relations (r = 2), the former employs the idea of pairing of elements among sets,
whereas the latter uses actual arithmetic products between elements of sets. Each of the fuzzy
sets could be thought of as a vector of membership values; each value is associated with a
particular element in each set. For example, for a fuzzy set (vector) A that has four elements,
hence column vector of size 4 × 1, and for a fuzzy set (vector)B that has five elements, hence
a row vector size of 1 × 5, the resulting fuzzy relation, R , will be represented by a matrix of
size 4 × 5, i.e., R will have four rows and five columns.

Fuzzy composition can be defined just as it is for crisp (binary) relations. Suppose R is a
fuzzy relation on the Cartesian space X × Y, S is a fuzzy relation on Y × Z, and T is a fuzzy
relation on X × Z; then fuzzy max–min composition is defined in terms of the set-theoretic
notation and membership function-theoretic notation in the following manner:

T =R ◦S
μT (x, z) = ( y €Y) V (μR(x, y) ∧ μ S(y, z))

2.4 PROCEDURE:

Enter following code in M file and save the file.

PROGRAM:

%Program to find a relation using Max-Min Composition


%Enter the two vectors whose relation is to be find
R=input('enter the first vector')
S=input ('enter the second vector')
% Find the size of two vectors
[m, n] =size (R)
[x,y]=size(S)
if (n==x)
for i=1:m
for j=1:y
c=R(i,:)
d=S (:, j)
f=d'
%Find the minimum of two vectors
q=min(c,f)
%Find the maximum of two vectors
h(i, j)=max(q);
end
end
%Print the result
display('the fuzzy relation between two vectors is');
display(h)
else
display(' can’t find the relationship ')
end

On running the above code, following output will appear in command window.
OUTPUT:

enter the first vector[0.2 0.3 0.4;0.3 0.5 0.7;1 0.8 0.6]
R
0.2000 0.3000 0.4000
0.3000 0.5000 0.7000
1.0000 0.8000 0.6000
enter the second vector[0.1 1;0.4 0.2;0.3 0.7]
s
0.1000 1.0000
0.4000 0.2000
0.3000 0.7000
Ans
the fuzzy relation between two vectors is
h
0.3000 0.4000
0.4000 0.7000
0.4000 1.0000

2.5 RESULT: Fuzzy relationship using max min composition is obtained.


EXPERIMENT NO. 3
Plot of Triangular and gaussian membership function in

3.1 Objective 2.2 Apparatus Required 2.3 Theory 2.4 Procedure 2.5 Result

3.1 OBJECTIVE:

1. Using MATLAB programming to draw triangular and Gaussian membership function.


Given x=0 to 10 with increment of 0.1. Triangular membership function is defined
between [5 6 7] and Gaussian membership is defined between 2 and 4.

2.2 MACHINES & APPARATUS USED:

MATLAB installed Computer (Windows operating system)

2.3 THEORY

Let S be the (universe) set of all real numbers, and let

Sf = { s € S | s is positive and large }.

This subset, Sf, is not well-defined in the classical set theory because, although the statement
“s is positive” is precise, the statement “s is large” is vague. However, if we introduce a
membership function that is reasonable and meaningful for a particular application for the
characterization or measure of the property “large,” say the one shown in Figure 1.2

Similarly, a membership function for the subset S f ~ = { s ∈ S | |s| is small } may be chosen
to be the one shown in Figure 1.3, where the cutting edge E is determined by the user
according to his concern in the application.

Other commonly used membership functions for fuzzy sets that are convenient in various
applications are shown in Figure 1.4, where we have normalized their maximum value to be
1, as usual, since 1 = 100% describes a full membership and is convenient to use. Obviously,
a membership function is a non-negative-valued function, which differs from the probability
density functions in that the area under the curve of a membership function need not be equal
to unity (in fact, it can be any value between 0 and ∞, including 0 and ∞). Another distinction
between the fuzzy set theory and the classical one (actually, the entire theory of classical
mathematics) is that a member of a fuzzy set may assume two or more (even conflicting)
membership values. For example, if we use the two membership functions shown in Figure
1.5 to measure “positive and large” and “negative and small,” respectively, then a member s
= 0.1 has the first membership value 0.095 and the second 0.08: they do not sum up to 1.0 nor
cancel out to be 0. Moreover, the two concepts are conflicting: s is positive and in the
meantime negative, a situation just like someone is old and also is young, which classical
mathematics cannot accept. Such a vague and conflicting description of a fuzzy set is
acceptable by the fuzzy mathematics, however, which turns out to be very useful in many
real-world applications. More importantly, the use of conflicting membership functions like
this will not cause any logical or mathematical problems in the consequence, provided that a
correct approach is taken in the sequel.

Fig. 1.2

Fig 1.3
3.4 PROCEDURE:

Enter following code in M file and save the file.

PROGRAM:

%Program to depict membership functions


x=(0:0.1:10)';
y1=gauss(x,[2 4]);
%Plot of Gaussian membership function
plot(x,y1)
hold
%Plot of Triangular membership function
y2=trim (x,[5 6 7]);
plot(x,y2)

On running the above code, following output will appear in command window.

OUTPUT:

Fig 3.1 Triangular and gaussian membership functions

3.5 RESULT: Plots of membership function obtained .


EXPERIMENT NO. 4
Lambda cut set relation

4.1 Objective 2.2 Apparatus Required 2.3 Theory 2.4 Procedure 2.5 Result

4.1 OBJECTIVE:

2. Using MATLAB program find the crisp lambda cut set relation for lambda=0.6.

The fuzzy matrix is given by:

[ ]
0.1 0. 6 0 .8 1
1 0. 7 0 .4 0. 2
0 0. 6 1 0. 5
R=
0.1 0. 5 1 0. 9

4.2 MACHINES & APPARATUS USED:

MATLAB installed Computer (Windows operating system)

4.3 THEORY

Consider a fuzzy seta , then define a lambda-cut set, Aλ, where 0 ≤ λ ≤ 1. The set Aλ is a
crisp set called the lambda (λ)-cut (or alpha-cut) set of the fuzzy set A
Any particular fuzzy set A can be transformed into an infinite number of λ-cut sets, because
there are an infinite number of values λ on the interval [0, 1].
Any element x of Aλ belongs to A with a grade of membership that is greater than or equal
to the value λ. The following example illustrates this idea. consider the discrete fuzzy set,
using Zadeh’s notation, defined on universe X = {a, b, c, d, e, f },

A= { 1a + 0.9b + 0.6c + 0.3d + 0.01e + 0f }


We can reduce this fuzzy set into several
λ-cut sets, all of which are crisp. For example, we can define λ-cut sets for the values of λ = 1,
0.9, 0.6, 0.3, 0+, and 0.
A1 = {a}, A0.9 = {a, b}
A0.6 = {a, b, c}, A0.3 = {a, b, c, d}
A0+ = {a, b, c, d, e}, A0 = X

By definition, λ = 0 produces the universe X, since all elements in the universe have at least a
0 membership value in any set on the universe. Since all A λ are crisp sets, all the elements
just shown in the example λ-cut sets have unit membership in the particular λ-cut set. For
example, for λ = 0.3, the elements a, b, c, and d of the universe have a membership of 1 in the
λ-cut set, A(0.3), and the elements e and f of the universe have a membership of 0 in the λ-cut
set, A(0.3).

We can express λ-cut sets using Zadeh’s notation. For the example, λ-cut sets for the values λ
= 0.9 and 0.25 are given here:

A0.9= { 1a + 0.9b + 0.6c + 0.3d + 0.01e + 0f } A0.25= { 1a + 1b + 1c + 1d + 0e + 0f }

4.4 PROCEDURE:

Enter following code in M file and save the file.

PROGRAM:

%Lambda Cut method of defuzzification


% Enter the given relational ·matrix
R=input('Enter the relational matrix')
% Enter the lambda value
lambda=input('enter the lambda value')
[m,n] =size (R);
for i=1:m
for j=1:n
if(R(i,j)<lambda)
b(i,j)=0;
else
b(i,j)=1;
end
end
end
% Output value
display('the crisp value is')
display(b)

On running the above code, following output will appear in command window.
OUTPUT:

Enter the relational matrix[O.l 0.6 0.8 1;1 0.7 0.4 0.2;0 0.6 1 0.5;
0.1 0.5 1 0.9]
R
0.1000 0.6000 0.8000 1. 0000
1. 0000 0.7000 0.4000 0.2000
0 0.6000 1. 0000 0.5000
0.1000 0.5000 1.0000 0.9000
enter the lambda value 0.6
lambda =
0.6000
Ans
the crisp value is
b
0111
1100
0110
0011

4.5 RESULT: lambda cut set for given fuzzy set is obtained
Experiment No. 5
5.1 Objective 5.2 Apparatus Required 5.3 Theory 5.4 Procedure 5.5 Result

5.1 OBJECTIVE: To study Speed control of motor by using Fuzzy Logic


Toolbox.

To control the speed of a motor by changing the input voltage .When a set point is defined, if
for some reason, the motor runs faster, we need to slow it down by reducing the input
voltage. If the motor slows below the set point, the input voltage must be increased so that the
motor speed reaches the set point.

5.2 MACHINES & APPARATUS USED

MATLAB installed Computer (Windows operating system)

5.3 PROCEDURE

Choose Input status words


Too slow
Just right
Too fast
Output action words be:
Less Voltage
No change
More Voltage

Open Fis Editor


Open Membership function editor
Design input membership function

Design output membership function


Define Rule base
1) If the motor is running too slow, then more voltage.
2) If motor speed is about right, then no change.
3) If motor speed is too fast, then less voltage.

Add rules
Open rule viewer
5.4 RESULT: Speed control of motor has been studied by using Fuzzy logic toolbox.

EXPERIMENT NO. 6
HEBB Rule

6.1 Objective 6.2 Apparatus Required 6.3 Theory 6.4 Procedure 6.5 Result

6.1 OBJECTIVE:

Write a program to construct and test auto-associative network for input vector using
HEBB/Outer Product Rule.

6.2 MACHINES & APPARATUS USED:

MATLAB installed Computer (Windows operating system)

6.3 THEORY

Biological neural systems are not born preprogramed with all the knowledge
and abilities that they will eventually have. A learning process that takes place
over a period of time somehow modifies the network to incorporate new information. The
basic theory comes from a 1949 book by Hebb, Organization of Behaviour.
The main idea was stated in the form of an assumption, which we
reproduce here for historical interest:
When an axon of cell A is near enough to excite a cell B and repeatedly or persistently
takes part in firing it, some growth process or metabolic change takes place in one
or both cells such that A's efficiency, as one of the cells firing B, is increased.
As with the McCulloch-Pitts model, this learning law does not tell the
whole story. Nevertheless, it appears in one form or another in many of the
neural-network models that exist today. Because the connection between neurons is through
the synapse, it is reasonable
to guess that whatever changes occur during learning take place there.
Hebb theorized that the area of the synaptic junction increased. More recent
theories assert that an increase in the rate of neurotransmitter release by the
presynaptic cell is responsible. In any event, changes certainly occur at the
synapse. If either the pre- or postsynaptic cell were altered as a whole, other
responses could be reinforced that are unrelated to the conditioning experiment

6.4 PROCEDURE:

Enter following code in M file and save the file.

PROGRAM:

clear all;
clc;
disp(' AUTO ASSOCIATIVE NETWORK-----HEBE RULE');
w=[0 0 0 0;0 0 0 0;0 0 0 0;0 0 0 0];
s=[1 1 1 -1];
t=[1 1 1 -1];
ip=[1 -1 -1 -1];
disp('INPUT VECTOR');
s
for i=1:4
for j=1:4
w(i,j)=w(i,j)+(s(i)*t(j));
end
end
disp ( 'WEIGHTS TO STORE THE GIVEN VECTOR IS' ) ;
w
disp('TESTING THE NET WITH VECTOR');
ip
yin=ip*w;
for i=1:4
if yin(i)>0
y(i)=1;
else
y(i)=-1;
end
end
if y==s
disp('PATTERN IS RECOGNIZED')
else
disp('PATTERN IS NOT RECOGNIZED')
end

On running the above code, following output will appear in command window.

OUTPUT:
>> AUTO ASSOCIATIVE NETWORK-----HEBE RULE
INPUT VECTOR
s=
1 1 1 -1
WEIGHTS TO STORE THE GIVEN VECTOR IS
w
1 1 1 -1
1 1 1 -1
1 1 1 -1
-1 -1 -1 1
TESTING THE NET WITH VECTOR
ip =
1 -1 -1 -1
PATTERN IS NOT RECOGNIZED

6.5 RESULT: Patterns were tested using Hebb rule

You might also like