How to determine the firing level for non-singleton inputs - A fuzzy logic problem
1 view (last 30 days)
Show older comments
Hi, i'm a new student of Fuzzy theory, and i'm trying to resolve the following Mamdani problem, considering that the input are nonsigleton.
I have 2 inputs: Temperature (low, medium, high) and price (low, medium, high), that are built using Gaussian and triangular functions, respectively:
% temperature
temperature=15:0.1:45;
tlow = gaussmf(temperature, [2.1 15]);%
tmedium = gaussmf(temperature, [2.1 24]);
thigh = gaussmf(temperature, [2.1 36.5]);
% price
price=1:0.1:6;
plow = trimf(price, [-0.3 1 2.4]);
pmedium = trimf(price, [1.7 3 4.3]);
phigh = trimf(price, [3.7 6 8.3]);
The output function of the problem is the soda consumption (low, medium, high), and is a triangular function:
% consumption
consumption=500:0.1:6000;
clow = trimf(consumption, [-1000 500 2000]);
cmedium = trimf(consumption, [1500 3000 4500]);
chigh = trimf(consumption, [4000 6000 8000]);
Rules:
1) if TEMPERATURE is low and PRICE is low then CONSUMPTION is big;
2) if TEMPERATURE is low and PRICE is medium then CONSUMPTION is medium;
3) if TEMPERATURE is low and PRICE is high then CONSUMPTION is small;
4) if TEMPERATURE is medium and PRICE is low then CONSUMPTION is big;
5) if TEMPERATURE is medium and PRICE is medium then CONSUMPTION is medium;
6) if TEMPERATURE is medium and PRICE is high then CONSUMPTION is small;
7) if TEMPERATURE is high and PRICE is low then CONSUMPTION is big;
8) if TEMPERATURE is high and PRICE is medium then CONSUMPTION is medium;
9) if TEMPERATURE is high and PRICE is high then CONSUMPTION is small.
I know that first it is necessary calculate the firing level, but i don't know how. Somebody can help me with this problem?
2 Comments
Answers (1)
Sam Chak
on 14 Apr 2025
Hi @Emanuel
With all the membership functions well-defined and the number of fuzzy rules sufficient (
), using specific functions from the Fuzzy Logic Toolbox, or better yet, directly designing the fuzzy system using the Fuzzy Logic Designer app, can skip the computation of firing level, and thus simplifying the process of fuzzy system design. However, the firing level can be computed using evalfis() command.
), using specific functions from the Fuzzy Logic Toolbox, or better yet, directly designing the fuzzy system using the Fuzzy Logic Designer app, can skip the computation of firing level, and thus simplifying the process of fuzzy system design. However, the firing level can be computed using evalfis() command.fis = mamfis;
%% input 1: Temperature
fis = addInput(fis, [15, 45], 'Name', 'Temperature');
fis = addMF(fis, 'Temperature', 'gaussmf', [2.1 15.0], 'Name', 'Low');
fis = addMF(fis, 'Temperature', 'gaussmf', [2.1 24.0], 'Name', 'Medium');
fis = addMF(fis, 'Temperature', 'gaussmf', [2.1 36.5], 'Name', 'High');
%% input 2: Price
fis = addInput(fis, [1, 6], 'Name', 'Price');
fis = addMF(fis, 'Price', 'trimf', [-0.3 1 2.4], 'Name', 'Low');
fis = addMF(fis, 'Price', 'trimf', [ 1.7 3 4.3], 'Name', 'Medium');
fis = addMF(fis, 'Price', 'trimf', [ 3.7 6 8.3], 'Name', 'High');
%% Output: Consumption
fis = addOutput(fis, [500, 6000], 'Name', 'Consumption');
fis = addMF(fis, 'Consumption', 'trimf', [-1000 500 2000], 'Name', 'Small');
fis = addMF(fis, 'Consumption', 'trimf', [ 1500 3000 4500], 'Name', 'Medium');
fis = addMF(fis, 'Consumption', 'trimf', [ 4000 6000 8000], 'Name', 'Big');
%% Fuzzy rules
rules = [
"If Temperature is Low and Price is Low then Consumption is Big" % Rule 1
"If Temperature is Low and Price is Medium then Consumption is Medium" % Rule 2
"If Temperature is Low and Price is High then Consumption is Small" % Rule 3
"If Temperature is Medium and Price is Low then Consumption is Big" % Rule 4
"If Temperature is Medium and Price is Medium then Consumption is Medium" % Rule 5
"If Temperature is Medium and Price is High then Consumption is Small" % Rule 6
"If Temperature is High and Price is Low then Consumption is Big" % Rule 7
"If Temperature is High and Price is Medium then Consumption is Medium" % Rule 8
"If Temperature is High and Price is High then Consumption is Small" % Rule 9
];
fis = addRule(fis, rules);
figure
subplot(211)
plotmf(fis, 'input', 1, 3001), grid on, title('Input fuzzy sets for Temperature')
subplot(212)
plotmf(fis, 'input', 2, 5001), grid on, title('Input fuzzy sets for Price')
figure
plotmf(fis, 'output', 1, 55001), grid on, title('Output fuzzy sets for Consumption')
figure
opt = gensurfOptions('NumGridPoints', 51);
gensurf(fis, opt); view(-37.5, 135)
figure
in_Temp = 25; % input value of Temperature
in_Price = 3; % input value of Price
[~, ~, ~, ~, ruleFiring] = evalfis(fis, [in_Temp, in_Price])
plotrule(fis, Inputs=[in_Temp, in_Price])
0 Comments
See Also
Categories
Find more on Time Series in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


