Let’s explore an example involving fuzzy logic, which is widely used to handle uncertainty and approximate reasoning.
Fuzzy logic extends traditional binary logic (true/false) by allowing partial truth values, typically ranging from $0$ (completely false) to $1$ (completely true).
This can be useful in various real-world applications like control systems, decision-making, and classification.
Problem: Fuzzy Temperature Classification
Suppose we want to classify temperature into three categories using fuzzy sets:
- Cold
- Warm
- Hot
Each category is represented by a membership function that assigns a membership value (between $0$ and $1$) to each temperature.
A higher value indicates a stronger association with that category.
Fuzzy Membership Functions
We’ll define the membership functions for each temperature category using triangular and trapezoidal functions:
- Cold: Defined by a triangular function that peaks at low temperatures.
- Warm: Defined by a trapezoidal function that covers the middle temperature range.
- Hot: Defined by a triangular function that peaks at high temperatures.
These membership functions are given as follows:
- Cold:
$$
\text{Cold}(x) = \begin{cases}
1 & x \leq 10 \
\frac{20 - x}{10} & 10 < x < 20 \
0 & x \geq 20
\end{cases}
$$ - Warm:
$$
\text{Warm}(x) = \begin{cases}
0 & x \leq 15 \
\frac{x - 15}{10} & 15 < x < 25 \
\frac{35 - x}{10} & 25 \leq x < 35 \
0 & x \geq 35
\end{cases}
$$ - Hot:
$$
\text{Hot}(x) = \begin{cases}
0 & x \leq 30 \
\frac{x - 30}{10} & 30 < x < 40 \
1 & x \geq 40
\end{cases}
$$
Objective
- Plot the membership functions for Cold, Warm, and Hot over a range of temperatures.
- Show how fuzzy logic allows overlapping categories, which allows for soft transitions between temperature classifications.
Python Code
Here’s the $Python$ code to define the membership functions and plot them:
1 | import numpy as np |
Explanation of the Code
- Membership Functions:
- We define functions for Cold, Warm, and Hot categories based on the temperature.
Each function returns a membership value for a given temperature.
- We define functions for Cold, Warm, and Hot categories based on the temperature.
- Plotting:
- Temperature values are generated from $0$ to $50$°C, and each membership function is evaluated over this range.
- The plot shows how the membership values vary with temperature for each fuzzy set (Cold, Warm, Hot).
Visualization

The plot shows:
- Cold Curve (Blue): Decreases from a membership of $1$ at low temperatures to 0 as temperatures approach $20$°C.
- Warm Curve (Orange): Peaks in the middle temperature range ($15$–$35$°C), with membership values gradually increasing and then decreasing.
- Hot Curve (Red): Increases as temperature rises above $30$°C, reaching a maximum membership of $1$ at $40$°C and beyond.
Interpretation
- Overlap: The fuzzy sets overlap, allowing a temperature (e.g., $25$°C) to be partially classified as both Warm and Hot.
This overlap represents the soft boundary between classifications, which is a key feature of fuzzy logic. - Partial Membership: Temperatures do not need to belong exclusively to one category.
For instance, $18$°C might be $0.2$ Cold and $0.8$ Warm. - Applications: Fuzzy logic is widely used in systems where clear-cut boundaries are impractical, such as thermostats, climate control, and decision-making systems that need to handle ambiguity and gradual transitions.







