Assingment
Assingment
MATLAB Code:
clc;
clear all;
X=(0:0.1:10);
Y=gaussmf(X,[0.5 2]);
plot(X,Y,'LineWidth',2.0);
ylim([0 1]);
ylabel("Membership Grades");
set(gca,'FontName','Times','Fontsize',15.0);
Python Code:
import numpy as np
import matplotlib.pyplot as plt
X = np.arange(0, 10.1, 0.1)
sigma = 0.5
mean = 2
Y = np.exp(-((X - mean)**2) / (2 * sigma**2))
plt.plot(X, Y, linewidth=2.0)
plt.ylim([0, 1])
plt.ylabel("Membership Grades", fontsize=15)
plt.gca().set_xlabel("X", fontsize=15)
plt.gca().tick_params(axis='both', which='major', labelsize=15)
plt.gca().set_title("Gaussian Membership Function", fontsize=15)
plt.show()
4.General Bell Shaped Membership Function:
MATLAB Code:
clc
clear all
X=(0:0.1:10)
Y=gbellmf(X,[1 4 6]);
plot(X,Y,'LineWidth',2.0)
ylim([0 1])
ylabel("Membership Grades")
set(gca,'FontName','Times','Fontsize',15.0)
Python Code:
import numpy as np
import matplotlib.pyplot as plt
def gbellmf(x, params):
a, b, c = params
return 1 / (1 + np.abs((x - c) / a)**(2 * b))
X = np.arange(0, 10.1, 0.1)
Y = gbellmf(X, [1, 4, 6])
plt.plot(X, Y, linewidth=2.0)
plt.ylim([0, 1])
plt.ylabel("Membership Grades", fontsize=15)
plt.gca().set_xlabel("X", fontsize=15)
plt.gca().tick_params(axis='both', which='major', labelsize=15)
plt.gca().set_title("Generalized Bell Membership Function", fontsize=15)
plt.show()
5.Sigmoidal Membership Function:
MATLAB Code:
clc
clear all
X=(0:0.1:10)
Y=sigmf(X,[4 5]);
plot(X,Y,'LineWidth',2.0)
ylim([0 1])
ylabel("Membership Grades")
set(gca,'FontName','Times','Fontsize',15.0)
Python Code:
import numpy as np
import matplotlib.pyplot as plt
def sigmf(x, params):
b, c = params
return 1 / (1 + np.exp(-b * (x - c)))
X = np.arange(0, 10.1, 0.1)
Y = sigmf(X, [4, 5])
plt.plot(X, Y, linewidth=2.0)
plt.ylim([0, 1])
plt.ylabel("Membership Grades", fontsize=15)
plt.gca().set_xlabel("X", fontsize=15)
plt.gca().tick_params(axis='both', which='major', labelsize=15)
plt.gca().set_title("Sigmoidal Membership Function", fontsize=15)
plt.show()
6.𝝅 Membership Function:
MATLAB Code:
clc
clear all
X=(0:0.1:10)
Y=pimf(X,[2 5 8 10]);
plot(X,Y,'LineWidth',2.0)
ylim([0 1])
ylabel("Membership Grades")
set(gca,'FontName','Times','Fontsize',15.0)
Python Code:
import numpy as np
import matplotlib.pyplot as plt
from skfuzzy.membership import trimf
X = np.arange(0, 10.1, 0.1)
Y = pimf(X, [2, 5, 8, 10])
plt.plot(X, Y, linewidth=2.0)
plt.ylim([0, 1])
plt.ylabel("Membership Grades", fontsize=15)
plt.gca().set_xlabel("X", fontsize=15)
plt.gca().tick_params(axis='both', which='major', labelsize=15)
plt.gca().set_title("Π (Pi) Membership Function", fontsize=15)
7.Left-Right Membership Function:
MATLAB Code:
clc;
clear all;
alpha=40;
beta=10;
c=70;
X=(0:0.1:100)';
for i=1:size(X,1);
if(X(i,1)>=c);
x1=(X(i,1)-c)/beta;
Y(i,1)=exp(-abs((x1)^3));
elseif (X(i,1)<=c);
x2=(c-X(i,1))/alpha;
Y(i,1)=exp(-abs((x2)^3));
end
end
figure;
plot(X,Y,'Linewidth',5.0);
ylim([0 1]);
ylabel("Membership Grades");
set(gca,'FontName','Times','Fontsize',15.0);
Python Code:
import numpy as np
import matplotlib.pyplot as plt
alpha = 40
beta = 10
c = 70
X = np.arange(0, 100.1, 0.1).reshape(-1, 1)
Y = np.zeros_like(X)
for i in range(X.shape[0]):
if X[i, 0] >= c:
x1 = (X[i, 0] - c) / beta
Y[i, 0] = np.exp(-abs(x1**3))
elif X[i, 0] <= c:
x2 = (c - X[i, 0]) / alpha
Y[i, 0] = np.exp(-abs(x2**3))
plt.plot(X, Y, linewidth=5.0)
plt.ylim(0, 1)
plt.ylabel("Membership Grades")
plt.gca().set_fontname("Times New Roman")
plt.gca().tick_params(labelsize=15)
plt.show()