0

I have 2 types of fuzzy function => triangle and trapazoid .. the triangle function take value and 3 points ( a,b,c's of triangle) and the trapazoid take value and 4 points ( a,b,c,d's of trapazoid )
i use the line equation to calculate the fuzzy value but the problem here is that function work if the points of set is like that [0,10,20,30] or [10,20,30,40] but when the set is [0,0,10,20] i got error cause of dividing on zero so it is possible to solve this problem using this equations This is triangle equation

def triangular(x, a, b, c):
    return max(min((x - a) / (b - a), (c - x) / (c - b)), 0)
def trap(x, a, b, c, d):
    return max(min((x - a) / (b - a), 1, (d - x) / (d - c)), 0)
  • 1
    You first need to decide what you want to do when the denominator is zero in one of your equations. The referenced equation doesn't say. Then, you can use a try/except block to catch the `ZeroDivisionError` and return the correct value or print a user-friendly error message. See https://www.geeksforgeeks.org/python-try-except/ for the basics of try/except. – Sarah Messer Dec 08 '22 at 21:49
  • That equation comes with a graph. How would you want the graph to look when a = b = 0? Do you want it to look like your triangular graph? – John Coleman Dec 08 '22 at 21:54
  • @John Coleman it will looked like this (blue triangle) https://user-images.githubusercontent.com/39713155/145992825-45fec009-db91-44b0-8ce2-f1ba2d19becc.png – Ahmed Abd El-Samie Dec 08 '22 at 22:01
  • @JohnColeman it will looked like this (blue triangle) user-images.githubusercontent.com/39713155/… – Ahmed Abd El-Samie Dec 08 '22 at 23:12

1 Answers1

0

Instead of using one mathematical expression, it may be easier to implement such membership functions using conditionals, and check for such conditions explicitly. It might also make sense to "sanity check" the incoming parameters, for example to make sure that they are strictly increasing.