Skip to content

Commit f4676a4

Browse files
Add files via upload
1 parent 6924d6d commit f4676a4

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Trapezoidal_Fuzzy.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import matplotlib.pyplot as plt
2+
3+
def trapezoidal(x, a, b, c, d):
4+
if x < a:
5+
return 0
6+
elif a <= x < b:
7+
return (x - a) / (b - a)
8+
elif b <= x <= c:
9+
return 1
10+
elif c < x <= d:
11+
return (d - x) / (d - c)
12+
else:
13+
return 0
14+
15+
a = float(input("Enter the value for a (left base): "))
16+
b = float(input("Enter the value for b (left top): "))
17+
c = float(input("Enter the value for c (right top): "))
18+
d = float(input("Enter the value for d (right base): "))
19+
20+
if a < b <= c < d:
21+
x = float(input("Enter a value for x: "))
22+
23+
val = trapezoidal(x, a, b, c, d)
24+
print(f"Value for x = {x}: {val}")
25+
26+
x_val = [a, b, c, d]
27+
y_val = [0, 1, 1, 0]
28+
29+
plt.plot(x_val,y_val, color="red", marker="o")
30+
plt.xlabel("X")
31+
plt.ylabel("Value")
32+
plt.title("Trapezoidal Fuzzification")
33+
plt.show()
34+
else:
35+
print("Invalid parameters: ensure that a < b <= c < d")

Triangular_Fuzzy.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import matplotlib.pyplot as plt
2+
def tri(x, a, b, c):
3+
if x < a:
4+
return 0
5+
elif a <= x < b:
6+
return (x - a) / (b - a)
7+
elif b <= x <= c:
8+
return (c - x) / (c - b)
9+
else:
10+
return 0
11+
12+
a = float(input("Enter the value for a (left base): "))
13+
b = float(input("Enter the value for b (peak): "))
14+
c = float(input("Enter the value for c (right base): "))
15+
16+
if a < b and b < c:
17+
x = float(input("Enter a value for x: "))
18+
19+
val = tri(x, a, b, c)
20+
if val is not None:
21+
print(f"Value for x = {x}: {val}")
22+
else:
23+
print("Invalid parameters: ensure that a < b < c")
24+
25+
x_val = [a,b,c]
26+
y_val = [0,1,0]
27+
28+
plt.plot(x_val,y_val,color="red",marker="o")
29+
plt.xlabel("X")
30+
plt.ylabel("Value")
31+
plt.title("Triangular Fuzzification" )
32+
plt.show()

0 commit comments

Comments
 (0)