SC Lab Record
SC Lab Record
“As complexity rises, precise statements lose meaning and meaningful statements
lose precision”
― Lotfi A. Zadeh
1
CONTENTS
Software used
MATLAB R2017a
Q1. Study about the IDENTITY FUNCTION
MATLAB PROGRAM
clear all
clc
x=0:1:5;
y=x;
plot(x,y)
xlabel('X-axis');
ylabel('Y-axis');
title('IDENTITY FUNCTION');
OUTPUT
𝟏; (𝒙) ≥ 𝜽
FUNCTION : 𝒇(𝒙) = { , 𝜽 = 𝒕𝒉𝒓𝒆𝒔𝒐𝒍𝒅 𝒗𝒂𝒍𝒖𝒆
𝟎; (𝒙) < 𝜃
MATLAB PROGRAM
clear all
clc
c=1;
x1=-5:0.1:10;
for x=-5:0.1:10
if x>=5
y(c)=1;
else
y(c)=0;
end
c=c+1;
end
plot(x1,y)
grid
xlabel('X-axis');
ylabel('Y-axis');
title('BINARY STEP FUNCTION');
OUTPUT
MATLAB PROGRAM
clear all
clc
x=0:0.01:5;
y1=(1+exp(-1*x));
y=1./(1+exp(-1*x));
plot(x,y)
xlabel('X-axis');
ylabel('Y-axis');
title('BINARY SIGMOID FUNCTION');
OUTPUT
𝟏−𝒆𝒙𝒑(−𝝈𝒙)
FUNCTION: 𝒇(𝒙) = 𝟏+𝒆𝒙𝒑(−𝝈𝒙)
MATLAB PROGRAM
clear all
clc
x=-5:0.01:5;
y1=(1-exp(-1*x));
y2=(1+exp(-1*x));
y=(1-exp(-1*x))./(1+exp(-1*x));
plot(x,y)
xlabel('X-axis');
ylabel('Y-axis');
title('BIPOLAR SIGMOIDAL HYPERBOLIC FUNCTION');
OUTPUT
𝟏; (𝒙) ≥ 𝜽
FUNCTION : 𝒇(𝒙) = { , 𝜽 = 𝒕𝒉𝒓𝒆𝒔𝒐𝒍𝒅 𝒗𝒂𝒍𝒖𝒆
−𝟏; (𝒙) < 𝜃
MATLAB PROGRAM
clear all
clc
c=1;
x1=-5:0.1:10;
for x=-5:0.1:10
if x>=5
y(c)=1;
else
y(c)=-1;
end
c=c+1;
end
plot(x1,y)
grid
xlabel('X-axis');
ylabel('Y-axis');
title('BIPOLAR STEP FUNCTION');
OUTPUT
MATLAB PROGRAM
clear all
clc
c=1;
x1=-2:0.1:2;
for x=-2:0.1:2;
if x>1
y(c)=1;
elseif (0<=x)&&(x<=1)
y(c)=x;
else
y(c)=0;
end
c=c+1;
end
plot(x1,y)
grid
xlabel('X-axis');
ylabel('Y-axis');
title('RAMP FUNCTION');
axis([-2 2 -0.5 1.5]);
OUTPUT
*********************************
Software used
MATLAB R2017a
Q1. Study of One input neuron network using different activation functions
MATLAB PROGRAM
nnd2n1
OUTPUT
1. Identity Function
[ Case 1 : w=2 , b=1] [ Case 2 : w=1 , b=-1]
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
2. Binary Sigmoid function
[ Case 1 : w=1 , b=-1] [ Case 2 : w=2 , b=1]
Q2. Study of Two input neuron network using different activation functions
MATLAB PROGRAM
nnd2n2
OUTPUT
1. Identity Function
2. [Case 1 : P1= 1 , P2= 1 , W(1,1) = -1 [Case 2 : P1= -1 , P2= -1 , W(1,1) = -1
W(1,2)=-1 , b=0] W(1,2)=-1 , b=0]
***************************************************
Software used
MATLAB R2017a
Q1. Implement AND-NOT function using MP neuron network taking binary data
Table
AND-NOT Function
W1 W2 Yinj
0 0 0
0 1 0
1 0 1
1 1 0
MATLAB PROGRAM
clc
clear all
%AND NOT FUNCTION
disp('Enter Weight');
w1=input('Weight w1=');
w2=input('Weight w2=');
disp('Enter the thresold value');
theta=input('theta');
y=[0 0 0 0]; x1=[0 0 1 1]; x2=[0 1 0 1]; z=[0 0 1 0]; con=1;
while con
zm=x1*w1+x2*w2;
for i=1:4
if zm(i)>=theta
y(i)=1
else
y(i)=0
end
end
disp('Output of Net');
disp(y);
OUTPUT
Enter Weight
Weight w1= 1
Weight w2= -1
Enter the thresold value
theta 1
zm =
0 -1 1 0
y=
0 0 0 0
y=
0 0 0 0
y=
0 0 1 0
y=
0 0 1 0
con =
Value of Weights
1
-1
thresold value
1
Q2. : Implement AND function using MP neuron network taking binary data
Table
AND Function
W1 W2 Yinj
0 0 0
0 1 0
1 0 0
1 1 1
MATLAB PROGRAM
clc
clear all
%AND FUNCTION
disp('Enter Weight');
w1=input('Weight w1=');
w2=input('Weight w2=');
disp('Enter the thresold value');
theta=input('theta');
y=[0 0 0 0]; x1=[0 0 1 1]; x2=[0 1 0 1]; z=[0 0 0 1];con=1;
OUTPUT
Enter Weight
Weight w1= 1
Weight w2= 1
Enter the thresold value
theta 2
zm =
0 1 1 2
y=
0 0 0 0
y=
0 0 0 0
0 0 0 0
y=
0 0 0 1
Output of Net
0 0 0 1
con =
Value of Weights
1
thresold value
2
Table
OR Function
W1 W2 Yinj
0 0 0
0 1 1
1 0 1
1 1 1
while con
zm=x1*w1+x2*w2
for i=1:4
if zm(i)>=theta
y(i)=1
else
y(i)=0
end
end
disp('Output of Net');
disp(y);
if (y==z)
con=0
else
disp('Net is not learning');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta=');
end
end
disp('Mc Culloch Pitt Net for OR function');
disp(y);
disp('Value of Weights');
disp(w1);
disp(w2);
disp('thresold value');
disp(theta);
OUTPUT
Enter Weight
Weight w1= 1
Weight w2= 1
Enter the thresold value
theta 1
0 1 1 2
y=
0 0 0 0
y=
0 1 0 0
y=
0 1 1 0
y=
0 1 1 1
Output of Net
0 1 1 1
con =
Value of Weights
1
1
thresold value
1
********************************************
Software used
MATLAB R2017a
Q1 : Implement XOR function using MP neuron network taking binary data
Table
XOR Function
W1 W2 Yinj
0 0 0
0 1 1
1 0 1
1 1 0
MATLAB PROGRAM
% XOR Function using MP Pattern
clear
clc
%Getting weights and thresold value
disp('Enter weights');
w11=input('Weight w11=');
w12=input('Weight w12=');
w21=input('Weight w21=');
w22=input('Weight w22=');
v1=input('Weight v1=');
v2=input('Weight v2=');
disp('Enter the thresold value');
theta=input('theta');
x1=[0 0 1 1];
x2=[0 1 0 1];
z=[0 1 1 0];
con=1;
Weight w11=1
Weight w12=-1
Weight w21=-1
Weight w22=1
Weight v1=1
Weight v2=1
theta1
Output of net
0 1 1 0
-1
weights of neuron z2
-1
weights of neuron y
1
Thresold Value
1
****************************************************
Software used
MATLAB R2017a
Q1. Implement AND-NOT function using PERCEPTRON network taking bipolar
data
Table
AND-NOT Function
X1 X2 Yinj
-1 -1 1
-1 1 -1
1 -1 1
1 1 -1
MATLAB PROGRAM
% 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 Thresold Vaule=');
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
OUTPUT
FINAL BIAS
-1
Q2.Write a MATLAB program for Perceptron net for an AND function with bi-
polar inputs and targets.
X1 X2 Y
-1 -1 -1
-1 1 1
1 -1 1
1 1 1
MATLAB PROGRAM
clear all;
clc;
x=[1 1 -1 -1;1 -1 1 -1];
t=[1 1 1 -1];
w=[0 0];
b=0;
alpha=input('Enter Learing 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
OUTPUT
*****************************************************
Software used
MATLAB R2017a
Q1. Implement XOR function using PERCEPTRON network taking bipolar data
X1 X2 Y
-1 -1 -1
-1 1 1
1 -1 1
1 1 -1
MATLAB PROGRAM
clear all;
clc;
x=[1 1 -1 -1;1 -1 1 -1];
t=[-1 1 1 -1];
w=[0 0];
b=0;
alpha=input('Enter Learing 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
OUTPUT
****************************************************
Software used
MATLAB R2017a
Q1.Write a MATLAB program for Hebb net to classify two dimensional input
patterns in bipolar with their tagets given below, ‘*’ indicates a ‘+1’ and ‘.’
Indicates ‘-1’.
MATLAB PROGRAM
clear all
clc
E=[1 1 1 1 1 -1 -1 -1 1 1 1 1 1 -1 -1 -1 1 1 1 1];
F=[1 1 1 1 1 -1 -1 -1 1 1 1 1 1 -1 -1 -1 1 -1 -1 -1];
x(1,1:20)=E;
x(2,1:20)=F;
w(1:20)=0;
t=[1 -1];
b=0;
for i=1:2
w=w+x(i,1:20)*t(i);
b=b+t(i);
end
OUTPUT
**********************************************
Software used
MATLAB R2017a
Q1. Develop a MATLAB program for OR function with bipolar inputs and
targets using ADALINE network.
MATLAB PROGRAM
clear all;
clc;
disp('Adaline network for OR function Bipolar inputs and targets');
x1=[1 1 -1 -1];
x2=[1 -1 1 -1];
x3=[1 1 1 1];
t=[1 1 1 -1];
w1=0.1;w2=0.1;b=0;
alpha=0.1;
e=2;
delw1=0;delw2=0;delb=0;
epoch=0;
while(e>1.018)
epoch=epoch+1;
e=0;
OUTPUT
Adaline network for OR function Bipolar inputs and targets
wc =
0.0800 0.0800 0.0800
w=
0.1800 0.1800 0.0800
pnt =
1.0000 1.0000 1.0000 0.2000 1.0000 0.0800 0.0800 0.0800
0.1800 0.1800 0.0800
wc =
0.0920 -0.0920 0.0920
w=
0.2720 0.0880 0.1720
pnt =
1.0000 -1.0000 1.0000 0.0800 1.0000 0.0920 -0.0920 0.0920
0.2720 0.0880 0.1720
Q2. Develop a MATLAB program for AND function with bipolar inputs and
targets using ADALINE network
X1 X2 Y
-1 -1 -1
-1 1 -1
1 -1 -1
1 1 1
clear all;
clc;
disp('Adaline network for AND function Bipolar inputs and targets');
x1=[1 1 -1 -1];
x2=[1 -1 1 -1];
x3=[1 1 1 1];
t=[1 -1 -1 -1];
w1=0.1;w2=0.1;b=0;
alpha=0.1;
e=2;
delw1=0;delw2=0;delb=0;
epoch=0;
while(e>1.018)
epoch=epoch+1;
e=0;
for i=1:4
nety(i)=w1*x1(i)+w2*x2(i)+b;
nt=[nety(i) t(i)];
delw1=alpha*(t(i)-nety(i))*x1(i);
delw2=alpha*(t(i)-nety(i))*x2(i);
delb=alpha*(t(i)-nety(i))*x3(i);
wc=[delw1 delw2 delb]
w1=w1+delw1;
w2=w2+delw2;
b=b+delb;
w=[w1 w2 b]
x=[x1(i) x2(i) x3(i)];
pnt=[x nt wc w]
end
for i=1:4
nety(i)=w1*x1(i)+w2*x2(i)+b;
e=e+(t(i)-nety(i))^2;
end
end
OUTPUT
wc =
w=
pnt =
Columns 1 through 10
Column 11
0.0800
wc =
w=
pnt =
Columns 1 through 10
Column 11
-0.0280
wc =
w=
Columns 1 through 10
Column 11
-0.1468
wc =
w=
pnt =
Columns 1 through 10
Column 11
wc =
w=
pnt =
Columns 1 through 10
-0.5582
wc =
w=
pnt =
Columns 1 through 10
Column 11
-0.4996
**************************************************
Software used
MATLAB R2017a
Q1.Write a MATLAB program to generate XOR function for bipolar inputs and
targets using MADALINE network.
MATLAB PROGRAM
clc;
clear;
x=[1 1 -1 -1;1 -1 1 -1];
t=[-1 1 1 -1];
w=[0.05 0.1;0.2 0.2];
b1=[0.3 0.15];
v=[0.5 0.5];
b2=0.5;
con=1;
alpha=0.5;
epoch=0;
while con
con=0;
for i=1:4
for j=1:2
zin(j)=b1(j)+x(1,i)*w(1,j)+x(2,i)*w(2,j);
if zin(j)>=0
z(j)=1;
else
z(j)=-1;
end
end
yin=b2+z(1)*v(1)+z(2)*v(2);
if yin>=0
y=1;
else
y=-1;
Guided By: MISS VANDANA JHA
Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
end
if y~=t(i)
con=1;
if t(i)==1
if abs(zin(1))>abs(zin(2))
k=2;
else
k=1;
end
b1(k)=b1(k)+alpha*(1-zin(k));
w(1:2,k)=w(1:2,k)+alpha*(1-zin(k))*x(1:2,i);
else
for k=1:2
if zin(k)>0;
b1(k)=b1(k)+alpha*(-1-zin(k));
w(1:2,k)=w(1:2,k)+alpha*(-1-zin(k))*x(1:2,i);
end
end
end
end
end
epoch=epoch+1;
end
disp('Weight matrix of hidden layer');
disp(w);
disp('Bias of hidden layer');
disp(b1);
disp('Total Epoch');
disp(epoch);
OUTPUT
X1 X2 Y
-1 -1 1
-1 1 -1
1 -1 -1
1 1 1
MATLAB PROGRAM
clc;
clear;
x=[1 1 -1 -1;1 -1 1 -1];
t=[1 -1 -1 1];
w=[0.05 0.1;0.2 0.2];
b1=[0.3 0.15];
v=[0.5 0.5];
b2=0.5;
con=1;
alpha=0.5;
epoch=0;
while con
con=0;
for i=1:4
for j=1:2
zin(j)=b1(j)+x(1,i)*w(1,j)+x(2,i)*w(2,j);
if zin(j)>=0
z(j)=1;
else
z(j)=-1;
end
end
yin=b2+z(1)*v(1)+z(2)*v(2);
if yin>=0
y=1;
else
y=-1;
end
if y~=t(i)
con=1;
if t(i)==1
b1(k)=b1(k)+alpha*(-1-zin(k));
w(1:2,k)=w(1:2,k)+alpha*(-1-zin(k))*x(1:2,i);
end
end
end
e
end
epoch=epoch+1;
end
disp('Weight matrix of hidden layer');
disp(w);
disp('Bias of hidden layer');
disp(b1);
disp('Total Epoch');
disp(epoch);
OUTPUT
****************************************************
Software used
MATLAB R2017a
Q1 : Write a MATLAB program for basic tipping problem using Fuzzy Logic
and show its output according to given conditions
PROGRAM
1. Rule
2. SURFACE
************************************************