Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/ai4untitledPlain Text
def trapezoidal_membership(x, a, b, c, d):
"""Calculates fuzzy membership value for a trapezoidal distribution."""
if x <= a or x >= d:
return 0.0
elif b <= x <= c:
return 1.0
elif a < x < b:
return (x - a) / (b - a)
elif c < x < d:
return (d - x) / (d - c)
return 0.0
# Test with parameters: a=1, b=3, c=6, d=8
a, b, c, d = 1, 3, 6, 8
test_inputs = [0, 2, 4.5, 7, 9]
print(f"Trapezoidal Function (a={a}, b={b}, c={c}, d={d}):")
for x in test_inputs:
degree = trapezoidal_membership(x, a, b, c, d)
print(f" Input x = {x:<4} -> Membership Degree = {degree:.2f}")630 chars · codepastes.com