Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

.

INDEX

S.No Title Remarks


1 Implementation of fuzzy sets on classical
set using MATLAB
2 Write a program in MATLAB to perform
Union, Intersection and Complement
operations.

3 Implementation of Fuzzy Inference


system using MATLAB.
4 Implementing simple perceptron model to
show effects of input, weights and bias on
decision boundary
5 Design, implement and train a feed
forward ANN for pattern recognition
problems.
6 Implementation of fuzzy based controller
on washing machine.
7 Implementation of perceptron learning
algorithm in MATLAB
Experiment 1

Objective:
Implementation of fuzzy sets on classical set using MATLAB
Software Required:
Windows OS, MATLAB, MS-word
CODE:
N = 501; legend('A','B','A+B')
minX = -20; subplot(2,1,2)
maxX = 20; plot(x,A,'--',x,B,':',x,Csub,'c')
x = linspace(minX,maxX,N); title('Fuzzy Subtraction, A-B')
A=trapmf(x,[-10-213]); legend('A','B','A-B')
B = gaussmf(x,[2 5]); figure
Csum = fuzarith(x,A,B,'sum'); subplot(2,1,1)
Csub = fuzarith(x,A,B,'sub'); plot(x,A,'--',x,B,':',x,Cprod,'c')
Cprod = fuzarith(x,A,B,'prod'); title('Fuzzy Multiplication, A*B')
Cdiv = fuzarith(x,A,B,'div'); legend('A','B','A*B')
figure subplot(2,1,2)
subplot(2,1,1) plot(x,A,'--',x,B,':',x,Cdiv,'c')
plot(x,A,'--',x,B,':',x,Csum,'c') title('Fuzzy Division, A/B')
title('Fuzzy Addition, A+B') legend('A','B','A/B')
OUTPUT:
Experiment- 2
Objective
Writea program in MATLAB to perform Union,IntersectionandComplement
operations.
Software Required:
Windows OS, MATLAB, MS-word

CODE:
%Enter Data
u=input('Enter First Matrix');
v=input('Enter Second Matrix');
%To Perform Operations
w=max(u,v);
p=min(u,v);
q1=1-u;
q2=1-v;
%Display Output
display('Union Of Two Matrices');
display(w);
display('Intersection Of Two Matrices');
display(p);
display('Complement Of First Matrix');
display(q1);
display('Complement Of Second Matrix');
display(q2);
Output:-

Enter First Matrix [0.3 0.4]


Enter Second Matrix [0.1 0.7]

UnionOfTwoMatrices
w =0.3000 0.7000

Intersection Of Two Matrices


p = 0.1000 0.4000

Complement Of First Matrix


q1 =0.70000.6000

Complement Of Second Matrix


q2 =0.90000.3000
Experiment 3

Program No. 5

To implement FIS Editor.


Objective
Implementation of Fuzzy Inference system using Matlab.
FIS stands for Fuzzy Inference System.In FIS fuzzy rulesare used for approximate reasoning.It
Software Required:
is the logical framework that allows us to design reasoning systems based on fuzzy set theory.
Windows OS, MATLAB, MS-word
To illustrate these concepts we use example of Water Tank:-

FIS editor consists of following units:-

i) Input

ii) Inference System

iii) Output

The Water Level is considered as the Input variable and Valve status is taken as Output Variable.
The Input-Output Variable’s Membership functions should be plotted along with their ranges:-

The following screen appearance is obtained by clicking on the FIS Rule system indicator:-

Rules are added by selecting variable’s values and clicking on add rule menu each time a new

rule is added.

The fuzzy Rules defined for water tank are:-

IF level is ok,THEN there is no change in valve.

IF level is low,THEN valve is open in fast mode.

IF level is high,THEN valve is closed in fast mode.


The result is displayed as plots of input-output membership functions :-

Water Level(ok,low,high)

Valve Status(no change,open fast,closed fast)

The output in accordance with the input and rules provided by user is shown as(view-rule

viewer):-
Output
Experiment- 4

Objective:
Write Implementing
aIm
MpATlemLeAB tatip
nsimplerogr
on of fa
umzzyfose
perceptron r tP
s eon
model rctocleshow
patssireffects
on
can eof
l set tfuinput,
osir nan AN ATD
gweights
M LA fBunction
and bias onwith bipolarboundary
decision
iputs
n
Software Required:
Windows OS, MATLAB, MS-word

CODE:
% Perceptron for AND Function

clear;

clc;

x=[1 1 -1 -1;1 -1 1 -1];

t=[1 -1 -1 -1];

w=[0 0];

b=0;

alpha=input('Enter Learning rate=');

theta=input('Enter Threshold Value=');

con=1;

epoch=0;

while con

con=0;

for i=1:4

yin=b+x(1,i)*w(1)+x(2,i)*w(2);

if yin>theta

y=1;

end

if yin<=theta & yin>=-theta


y=0;

end

if yin<-theta

y=-1;

end

if y-t(i)

con=1;

for j=1:2

w(j)=w(j)+alpha*t(i)*x(j,i);

end

b=b+alpha*t(i);

end

end

epoch=epoch+1;

end

disp('Perceptron for AND Function');

disp('Final Weight Matrix');

disp(w);

disp('Final Bias');

disp(b);
Output :-

Enter Learning rate=1

Enter Threshold Value=0.5

Perceptron for AND Function

Final Weight Matrix

1 1

Final Bias

-1
Experiment 5

Objective:
Design, implement and train a feed forward ANN for pattern recognition problems.

Software Required:
Windows OS, MATLAB, MS-word

Code:
[X,T] = bodyfat_dataset;
net = fitnet(15);
view(net)
[net,tr] = train(net,X,T);
Nntraintool
nntraintool('close') plotperform(tr)
graph testX = X(:,tr.testInd);
testT = T(:,tr.testInd);
testY = net(testX);
perf = mse(net,testT,testY)
perf = 33.2344
Y = net(X);
plotregression(T,Y)
e = T - Y;
ploterrhist(e)
 Outputs and graphs
View of network

Training of network
Best Validatio n Performance is 34.4082 at ep.Fch 3

T-igure.” Regression ol Network

Errors

Error Histogram with 20 Bins


Experiment 6

Objective:
Implementation of fuzzy based controller on washing machine.
Software Required:

Windows OS, MATLAB, MS-word


CODE:
a = readfis ('washtime.fis')
a = name: 'washtime'
type: 'mamdani'
andMethod: 'min'
orMethod: 'max'
defuzzMethod: 'centroid'
impMethod: 'min'
aggMethod: 'max'

input: [1x5 struct]


output: [1x1 struct]
rule: [1x216 struct]
>>a = readfis('washtime');
evalfis([0.5 0.5 0.5 0.5 20 ], a)
ans = 12.6650
>>a=readfis('washtime');
evalfis([0.635 .245.5.520 ], a)
ans = 22.0962
plotfis(a),
International Journal of Latest Trends in Engineering and Technology (IJLTET) ISSN: 2278-621X

ans = 12.6650
>>a=readfis('washtime');
evalfis([0.635 .245 .5 .5 20 ], a)
ans = 22.0962
plotfis(a),

Figure. 2 Fuzzy Logic Controller for Wash Time

Using following commands we obtain the MFs for different LIs and LOs
plotmf(a,'input',2)
plotmf(a,'input',3)
plotmf(a,'output',1)
>>gensurf(a)

Figure.3 Surface Viewer for Wash time

http://dx.doi.org/10.21172/1.72.523 139 Vol 7 issue 2 July 2016


International Journal of Latest Trends in Engineering and Technology (IJLTET) ISSN: 2278-621X

>>ruleview(a)

Figure. 4 Rule Viewer For LO Wash Time


Evaluation of Real Values on the Bases of Rules for the Rinse Period-
a = readfis('rinseperiod.fis')
a = name: 'rinseperiod'
type: 'mamdani'
and Method: 'min'
or Method: 'max'
defuzz Method: 'centroid'
imp Method: 'min'
agg Method: 'max'
input: [1x5 struct]
output: [1x1 struct]
rule: [1x216 struct]
>>a = readfis('rinseperiod');
evalfis([0.5 0.5 0.5 0.5 20], a)
ans = 4.0000
>>a = readfis('rinseperiod');
evalfis([0.745 0.654 .325 .566 29], a)
ans = 7.8734
>>ruleview(a)

Figure. 5 Rule Viewers for Rinse Period

http://dx.doi.org/10.21172/1.72.523 140 Vol 7 issue 2 July 2016


International Journal of Latest Trends in Engineering and Technology (IJLTET) ISSN: 2278-621X

>>surfview(a)

Figure. 6 Surface Viewers for Rinse Period

>>plotfis(a)

Figure. 7 Fuzzy Logic Controller for LO rinse period


Evaluation Of Real Values On The Bases Of Rules For The Spin Period-
a = readfis('spinperiod.fis')
a = name: 'spinperiod'
type: 'mamdani'
and Method: 'min'
or Method: 'max'
defuzz Method: 'centroid'
imp Method: 'min'
agg Method: 'max'

http://dx.doi.org/10.21172/1.72.523 141 Vol 7 issue 2 July 2016


International Journal of Latest Trends in Engineering and Technology (IJLTET) ISSN: 2278-621X

input: [1x4 struct]


output: [1x1 struct]
rule: [1x25 struct]
a = readfis('spinperiod');
>>evalfis([0.5 0.5 15 0.5], a)
ans = 2.5000
a = readfis('spinperiod');
>>evalfis([0.2469 .02813 36.65 .1781], a)
ans = 0.5502
>>ruleview(a)

Figure. 8 Rule Viewer for Spin Period


>>plotfis(a)

Figure. 9 Fuzzy Logic Controller for Spin period

http://dx.doi.org/10.21172/1.72.523 142 Vol 7 issue 2 July 2016


International Journal of Latest Trends in Engineering and Technology (IJLTET) ISSN: 2278-621X

>>surfview(a)

Figure. 10 Surface Viewer for Spin period

By the use of fuzzy logic control we have been able to obtain a wash time, rinse period and spin period for
different type of dirt and different degree of dirt and different type of cloths. The conventional method required the
human interruption to decide upon what should be the wash time for different cloths. In other words this situation
analysis ability has been incorporated in the machine which makes the machine much more automatic and represents
the decision taking power of the new arrangement.
Here the sensors sense the input values and using the above Model the inputs are fuzzyfied and then by using
simple if-else rules and other simple fuzzy set operations the output fuzzy function is obtained and using the criteria
the output value for wash time, rinse period and spin period is obtained.
The results (the above plot) shows the way the machine will response in different conditions. This is quite
convincing and appropriate.
V. CONCLUSION
By the use of proposed fuzzy logic Controller, we have been able to obtain different Wash Time, Rinse Period,
Spin Period (output Variable) for different Type of Dirt, Dirtiness of Clothes, Types of Clothes, Mass of Clothes and
Temperature (Input Variable). This analysis also leads to saving in electrical energy and time for washing the
clothes by using proposed Washing Machine. This proposed advance and automatic sensor system based Washing
Machine depicts the advantage of Fuzzy Logic Controller in the conventional Washing Machine.
REFERENCES
[1] L.A. Zadeh, Fuzzy Sets, Information and Control, 338–353, (1965)
[2] Han H., Chun-Yi and Yury. S, Adaptive Control of a Class of Non-linear Systems with Non-Linearly Parameterized Fuzzy Approximation.
IEEE Transactions on Fuzzy Systems, V0l.9, No.2, 315-323, (2001)
[3] Workman, M. Hardware requirement for Fuzzy Logic Control Systems. Lubbock, TX: Texas Tech University, (1996)
[4] George J. Kilr and Bo Yuan, Fuzzy Sets and Fuzzy Logic (India: PHI, 1995)
[5] Sonia Chhabra , VHDL Implementation of Fuzzy Control System, (2006)
[6] Dharamniwas, Aziz Ahmad, Varun Redhu and Umesh Gupta, Liquid Level Control by Using Fuzzy Logic Controller, International Journal
of Advances in Engineering & Technology, (July 2012). ISSN: 2231-1963.
[7] Ge Zhe-Xue, Sun Zhi-Qiang. Neural N/w Theory and the realization MATLAB (Beijing: Electronics industry publishing, 2007)
th
[8] Lohani P., and Hasan,S.R..Design of an Improved Controller Microchip For Washing Machine, 16 Annual Electronics New Zealand
Conference (pp. 20-26).Dunedin : Otago University (2009)
[9] Manish Aggarwal, Fuzzy Logic Controller for Washing Machine, IIT Kharagpur (2011).

http://dx.doi.org/10.21172/1.72.523 143 Vol 7 issue 2 July 2016


Experiment 7

Objective:
Implementation of perceptron learning algorithm in MATLAB
Software Required:
Windows OS, MATLAB, MS-word
CODE:
input = [0 0; 0 1; 1 0; 1 1];

numIn = 4;

desired_out = [0;1;1;1];

bias = -1;

coeff = 0.7;

rand('state',sum(100*clock));

weights = -1*2.*rand(3,1);

iterations = 10;

The feed forward perceptron code:


for i = 1:iterations

out = zeros(4,1);

for j = 1:

numIn y = bias*weights(1,1)+…

input(j,1)*weights(2,1)+input(j,2)*weights(3,1);

out(j) = 1/(1+exp(-y));

delta = desired_out(j)-out(j);

weights(1,1) = weights(1,1)+coeff*bias*delta;

weights(2,1) = weights(2,1)+coeff*input(j,1)*delta;

weights(3,1) = weights(3,1)+coeff*input(j,2)*delta;

end

end
OUTPUT:
When running the perceptron over 10 iterations, the outputs begin to converge, but are
still not precisely as expected:

out =

0.3756

0.8596
0.9244

0.9952

weights =

0.6166

3.2359

2.7409

As the iterations approach 1000, the output converges towards the


desired output.
out =

0.0043

0.9984

0.9987

1.0000

weights =

5.4423

12.1084

11.8823

You might also like