0% found this document useful (0 votes)
16 views

Fuzzy Logic Experiments

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Fuzzy Logic Experiments

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Performing Union, Intersection and Complement Operations

Ex. No: 1
Date:

Aim :
To write a Program in MATLAB to perform union, intersection and complement
operations of fuzzy set.

Algorithm:
1. Read the membership values of two fuzzy sets.
2. Perform union operation by using max( ) function.
3. Perform intersection operation by using min( ) function.
4. Perform complement operation by subtracting membership value from 1
5. Display the result.

Program:

% Enter the membership value of fuzzy set


u = input (‘Enter the membership value of First Fuzzy set’);
v = input (‘Enter the membership value of Second Fuzzy set’);
%performs Union, Intersection and Complement operations
w=max (u, v);
p=min (u, v);
q1=1-u;
q2=1-v;
%Display Output
disp(‘Union of Two Fuzzy sets’);
disp(w);
disp(‘Intersection of Two Fuzzy sets’);
disp(p);
disp(‘Complement of First Fuzzy set’);
disp(q1);
disp(‘Complement of Second Fuzzy set’);
disp(q2);

Sample Input and Output:


Enter the membership value of First Fuzzy set [0.3 0.4]
Enter the membership value of Second Fuzzy set [0.1 0.7]
Union of Two Fuzzy sets
0.3000. 0.7000
Intersection of Two fuzzy sets
0.1000 0.4000.
Complement of First Fuzzy set
0.7000 0.6000.
Complement of Second Fuzzy set
0.9000 0.3000.

Result:

Thus, the MATLAB program to perform Union, Intersection and Complement operations
of two Fuzzy sets has been executed successfully and the output is verified.
Plotting Various Membership Functions
Ex. No: 3
Date:

Aim:
To write a program in MATLAB to plot triangular, trapezoidal and bell shaped
membership functions.

Algorithm:

1. Set the limits of x axis.


2. Calculate y using trimf() function with three parameters for triangular membership
function.
3. Calculate y using trapmf() function with four parameters for trapezoidal membership
function.
4. Calculate y using gbellmf() function with three parameters for bell shaped membership
function.
5. Plot x and y values.

Program:

%Triangular membership function

x=(0.0:1.0:10.0)’;

y1= trimf(x, [1 3 5]);

subplot(311 )

plot(x,[y1]);

%Trapezoidal membership function

x=(0.0:1.0:10.0)’;

y1= trapmf(x, [1 3 5 7]);

subplot(312)

plot(x, [y1] );

%Bell-shaped membership function

x=(0.0:0.2:10.0);
y1=gbellmf (x,[3 5 7]);

subplot(313)

plot(x, [y1]);

Sample Input and Output:

Result:

Thus, the MATLAB program for plotting membership functions has been executed
successfully and the output is verified.
Implementation of Fuzzy Inference System
Ex. No: 5
Date:

Aim :
To implement a Fuzzy Inference System (FIS) for which the inputs, output and rules are
given as below.
INPUTS: Temperature and Cloud Cover
Temperature: {Freeze, Cool, Warm and Hot}
Cloud Cover: {Sunny, Partly Cloud and Overcast}
OUTPUT: Speed
Speed : {Fast and Slow}
RULES:
1. If cloud cover is Sunny and temperature is warm, then drive Fast
Sunny (Cover) and Warm (Temp) -> Fast (Speed)
2. If cloud cover is cloudy and temperature is cool, then drive Slow
Cloudy (Cover) and Cool (Temp) -> Slow (Speed)

Procedure
1. Go to command window in Matlab and type fuzzy.
2. Now, new Fuzzy Logic Designer window will be opened.
3. Input / Output Variable
a. Go to Edit Window and click Add variable.
b. As per our requirements create two input variables, Temperature and Cloud
Cover.
c. Create one output variable, Speed.
4. Temperature:
a. Double click the Temperature input variable in Fuzzy Logic Designer window.
b. New window will be opened and remove all the Membership Functions.
c. Now, Go to Edit and Click Add MFs and select the 4 Parameters for Temperature
Class.
d. Change the following fields as mentioned data in the given below table.
Inputs : Temperature Freezing, Cool, Warm and Hot
MF1: MF2: MF3: MF4:
Range : [0 110] Range : [0 110] Range : [0 110] Range : [0 110]
Name : Freezing Name : Cool Name : Warm Name : Hot
Type : trapmf Type : trimf Type : trimf Type : trapmf
Parameter [0 0 30 50] Parameter [30 50 70] Parameter [50 70 90] Parameter [70 90 110 110]

5. Similarly, add the data’s to the Cloud Cover variables and Speed variables.
6. Cloud Cover:

Inputs : Cloud Cover Sunny, Partly Cloud and Overcast


MF1: MF2: MF3:
Range : [0 100] Range : [0 100] Range : [0 100]
Name : Sunny Name : Partly Cloud Name : Overcast
Type : trapmf Type : trimf Type : trapmf
Parameter [0 0 20 40] Parameter [20 50 80] Parameter [60 80 100]

7. Speed:

Output : Speed Slow and Fast


MF1: MF2:
Range : [0 100] Range : [0 100]
Name : Slow Name : Fast
Type : trapmf Type : trapmf
Parameter [0 0 25 75] Parameter [25 75 100 100]

8. Goto Rules: Edit Rules


9. Add the Rules
Rule-1 : Sunny (Cover) and Warm (Temp) -> Fast (Speed)
Rule-2 : Cloudy (Cover) and Cool (Temp) -> Slow (Speed)
10. Go to view Rules
11. Exit.
Sample Input and Output:
Membership functions for Temperature variable

Membership functions for cloud over variable


Membership functions for speed variable

Created rules
Output

Result:
Thus a Fuzzy Inference System is implemented for temperature, cloud cover and speed
using the given rules.
Simple Fuzzy Set Operations
Ex. No: 6
Date:

Aim:
To write a MATLAB program to find algebraic sum, algebraic subtraction, algebraic
product, bounded sum, bounded subtraction and bounded product of two fuzzy sets.

Algorithm:
1. Read the values of the two fuzzy sets.
2. Perform the algebraic sum operation by,
A + B = (a + b) – (a * b)

3. Perform the algebraic subtraction operation by,


A – B = (a + b`) where b`= 1- b

4. Perform the algebraic product operation by,


A * B = (a * b)

5. Perform the bounded sum operation by,


A B = min [1, (a + b)]

6. Perform bounded subtraction operation by,


A B= max [0, (a - b)]
7. Perform bounded product operation by,
A B = max [0, (a + b - 1)]

8. Display the results

Program:
a= input(‘Enter the fuzzy set a’ )

b= input(‘Enter the fuzzy set b’)

c= a + b

d= a * b

as= c – d
e= 1 – b

ad= a + e

f= a – b

bs= min (1, c)

bd= max (0, f)

g= c – 1

bp= max (0,g)

disp(‘The algebraic sum’)

disp(as)

disp(‘The algebraic difference’)

disp(ad)

disp(‘The algebraic product’)

disp(d)

disp(‘The bounded sum’)

disp(bs)

disp(‘The bounded difference’)

disp (bd)

disp(‘The bounded product’)

disp(bp)
Output:

Enter fuzzy set a [1 0.5]

Enter fuzzy set b [0.4 0.2]

The algebraic sum

[1.0000 0.6000 ]

The algebraic difference

[1 0.9000]

The algebraic product

[0.4000 0.1000]

The bounded sum

[1.0000 0.7000]

The bounded difference

[0.6000 0.3000]

The bounded product

[0.4000 0]

Result:

Thus, a program to perform simple fuzzy set operations has been executed and successfully
verified.

You might also like