def trapmf(x, parameters):
    """
    Trapezoidal fuzzy membership function

    :param x: data point
    :param parameters: a list with 4 real values
    :return: the membership value of x given the parameters
    """
    if x < parameters[0]:
        return 0
    elif parameters[0] <= x < parameters[1]:
        return (x - parameters[0]) / (parameters[1] - parameters[0])
    elif parameters[1] <= x <= parameters[2]:
        return 1
    elif parameters[2] <= x <= parameters[3]:
        return (parameters[3] - x) / (parameters[3] - parameters[2])
    else:
        return 0
