here is the problem in fuzzy logic controller i dont understand how to fix flc in simulink and sort out this problem.

조회 수: 32 (최근 30일)
  댓글 수: 1
Umar
Umar 대략 7시간 전

Hi @Faria,

I read your comment. Let me explain what fuzzy rules are and what's happening in your screenshot.

Fuzzy rules are basically "if-then" statements that map input conditions to output actions in a fuzzy logic system. Unlike traditional programming where everything is either true or false (binary), fuzzy logic handles degrees of truth between 0 and 1, allowing systems to work with vague or imprecise information - just like human reasoning.

Think of it this way: When you decide how much to tip at a restaurant, you don't use strict mathematical formulas. Instead, you might think " If the service was good AND the food was delicious, then I'll give a generous tip." That's essentially what a fuzzy rule does!

Looking at your screenshot, your tipper23 system has three variables: service, food, and tip. Each variable can take values like NB, NM, NS, ZE, PS, PM, PB, which typically stand for Negative Big, Negative Medium, Negative Small, Zero, Positive Small, Positive Medium, and Positive Big respectively.

Each rule in your list follows a simple structure with an antecedent (the "if" part) and a consequent (the "then" part). For example, Rule 1 states: " If service is NB and food is NB then tip is NB" - meaning if the service is very poor AND the food is very bad, then the tip should be very small.

The key difference from traditional logic is that in fuzzy logic, variables can have partial truth values. For instance, service might be 70% "good" and 30% "average" at the same time, rather than strictly one or the other. The system evaluates all rules in parallel, and each rule contributes to the final output based on how well its conditions match the inputs.

Your 27 rules represent different combinations of service and food quality, each suggesting an appropriate tip level. When you input specific values for service and food quality, the fuzzy system will "fuzzify" these crisp inputs into membership degrees, apply all relevant rules, and then "defuzzify" the result back into a specific tip amount.

This is actually similar to the classic MATLAB tipper example, which uses rules like " If service is poor or food is rancid, then tip is cheap" to model realistic tipping behavior. The beauty of fuzzy logic is that it mimics how humans actually make decisions with incomplete or imprecise information, making it more intuitive to design and easier to understand than complex mathematical equations.

Hope this clears things up!

댓글을 달려면 로그인하십시오.

답변 (2개)

Umar
Umar 2025년 10월 19일 15:23
편집: Umar 2025년 10월 19일 15:24

Hi @Faria,

I have reviewed your attachment and posted comment. The warning in your provided attachment means your input signal to the Fuzzy Logic Controller is going slightly outside the range defined in your FIS file. For example, your message shows “input 1 expects a value in range [-0.2 1], but has a value of 1.00039.” When that happens, none of the membership functions are active, so no rules fire — which is why you also see “Defuzzified output value set to its mean range value.”

According to MathWorks documentation: “ If input values fall outside the range of the input variable, one possible consequence is that no membership function is activated -> no rule fires -> the block outputs the mean of the output range. ”

Source: MathWorks Fuzzy Logic Controller documentation https://www.mathworks.com/help/fuzzy/fuzzylogiccontroller.html

I will recommend the following steps to fix it.

1. Check the signal going into your FLC using a Scope or Display to see its actual range.

2. If it only slightly exceeds 1, add a Saturation block before the FLC with limits `[-0.2 1]`.

3. If the signal can genuinely go above 1, open your `.fis` in the FIS Editor and extend the input range (e.g. to `[-0.2 1.2]`). Make sure the membership functions cover that new range.

4. Optionally, add a “catch-all” membership function for extreme values so that at least one rule always fires.

Once your input stays within the FIS range (or the range is updated), the warnings will disappear and the controller will produce the correct output.

Hope this helps — it’s a very common issue when tuning DVR models that use fuzzy controllers.


Sam Chak
Sam Chak 대략 22시간 전
I have duplicated your problem here. You can follow @Umar's suggestions to resolve the issue. If they don't work or don't fit your application, then consider my proposed solutions. For the "No rules fired" issue, you can refer to my explanations in this thread #1 and this thread #2.
The general idea is to design the Membership Functions (MFs) to cover the entire universe of discourse so that the input fuzzy membership value corresponding to the input value in at least one fired rule is greater than 0. If all the MFs are listed in the rule base, this will ensure that at least one rule is fired, regardless of the input value. Even when the measured input value is outside the fuzzy input range, the rule with the MF defined at the extremes of the universe will still be activated, provided that the input fuzzy membership value corresponding to the extrema closest to the measured input value is greater than 0.
Please see examples in Solutions 1 and 2 below:
Problem:
fis = sugfis;
% Fuzzy Input
ui = [-0.2, +1.0]; % universe of discourse for input
p = diff(ui)/3; % parameter for input MFs
fis = addInput(fis, ui, 'Name', 'x');
fis = addMF(fis, 'x', 'trimf', [ui(1), ui(1)+p, ui(2)-p], 'Name', 'in1');
fis = addMF(fis, 'x', 'trimf', [ui(1)+p, ui(2)-p, ui(2)], 'Name', 'in2');
% Fuzzy Output
uo = [0.0, 2.5]; % universe of discourse for output
fis = addOutput(fis, uo, 'Name', 'y');
fis = addMF(fis, 'y', 'constant', uo(1), 'Name', 'ou1');
fis = addMF(fis, 'y', 'constant', uo(2), 'Name', 'ou2');
% Fuzzy Rules
rules = [
"x==in1 => y=ou1"
"x==in2 => y=ou2"
];
fis = addRule(fis, rules);
figure(1)
plotmf(fis, 'input', 1, 2001), grid on,
xlabel('x')
title('Input MFs')
% Input-Output relationship
figure(2)
[x, ~, y] = gensurf(fis, gensurfOptions('NumGridPoints', 12001));
plot(x, y), grid on
ylim([-0.5, 3.0])
xlabel('x'),
ylabel('y'),
title ('Input-Output relationship')
out = evalfis(fis, 1.00039)
Warning: Input 1 expects a value in range [-0.2 1], but has a value of 1.00039.
Warning: No rules fired for Output 1. Defuzzified output value set to its mean range value 1.25.
out = 1.2500
% Plot rules
figure(3)
plotrule(fis, Inputs=1.00039)
Note that the membership values of the Triangular functions defined at the extremes of the input universe are exactly 0. The horizontal dashed red lines in both fired rules in the rule inference diagram indicate that the input fuzzy membership values corresponding to the maximum range (x = 1) are exactly 0 (see Figure 3). This situation is interpreted as "No rules fired" and therefore, the defuzzified output value is set to its mean range value of (2.5 - 0)/2 = 1.25.
Solution 1: Reshape the Membership Functions so that they cover the entire the universe of discourse.
fis = sugfis;
% Fuzzy Input
ui = [-0.2, +1.0]; % universe of discourse for input
p = diff(ui)/3; % parameter for input MFs
fis = addInput(fis, ui, 'Name', 'x');
fis = addMF(fis, 'x', 'gaussmf', [p/2, ui(1)+p], 'Name', 'in1');
fis = addMF(fis, 'x', 'gaussmf', [p/2, ui(2)-p], 'Name', 'in2');
% Fuzzy Output
uo = [0.0, 2.5]; % universe of discourse for output
fis = addOutput(fis, uo, 'Name', 'y');
fis = addMF(fis, 'y', 'constant', uo(1), 'Name', 'ou1');
fis = addMF(fis, 'y', 'constant', uo(2), 'Name', 'ou2');
% Fuzzy Rules
rules = [
"x==in1 => y=ou1"
"x==in2 => y=ou2"
];
fis = addRule(fis, rules);
figure(4)
plotmf(fis, 'input', 1, 2001), grid on,
xlabel('x')
title('Input MFs')
% Input-Output relationship
figure(5)
[x, ~, y] = gensurf(fis, gensurfOptions('NumGridPoints', 12001));
plot(x, y), grid on
ylim([-0.5, 3.0])
xlabel('x'),
ylabel('y'),
title ('Input-Output relationship')
out = evalfis(fis, 1.00039)
Warning: Input 1 expects a value in range [-0.2 1], but has a value of 1.00039.
out = 2.4938
% Plot rules
figure(6)
plotrule(fis, Inputs=1.00039)
Note that the membership values of the Gaussian functions defined at the extremes of the input universe are greater than 0. Refer to the horizontal dashed red line of the fired Rule 2 in the rule inference diagram (Figure 6).
Solution 2: Insert additional Membership Functions so that they cover the entire the universe of discourse.
fis = sugfis;
% Fuzzy Input
ui = [-0.2, +1.0]; % universe of discourse for input
p = diff(ui)/3; % parameter for input MFs
fis = addInput(fis, ui, 'Name', 'x');
fis = addMF(fis, 'x', 'trimf', [ui(1), ui(1)+p, ui(2)-p], 'Name', 'in1');
fis = addMF(fis, 'x', 'trimf', [ui(1)+p, ui(2)-p, ui(2)], 'Name', 'in2');
fis = addMF(fis, 'x', 'linzmf', [ui(1), ui(1)+p], 'Name', 'in3');
fis = addMF(fis, 'x', 'linsmf', [ui(2)-p, ui(2)], 'Name', 'in4');
% Fuzzy Output
uo = [0.0, 2.5]; % universe of discourse for output
fis = addOutput(fis, uo, 'Name', 'y');
fis = addMF(fis, 'y', 'constant', uo(1), 'Name', 'ou1');
fis = addMF(fis, 'y', 'constant', uo(2), 'Name', 'ou2');
% Fuzzy Rules
rules = [
"x==in1 => y=ou1"
"x==in2 => y=ou2"
"x==in3 => y=ou1"
"x==in4 => y=ou2"
];
fis = addRule(fis, rules);
figure(7)
plotmf(fis, 'input', 1, 2001), grid on,
xlabel('x')
title('Input MFs')
% Input-Output relationship
figure(8)
[x, ~, y] = gensurf(fis, gensurfOptions('NumGridPoints', 12001));
plot(x, y), grid on
ylim([-0.5, 3.0])
xlabel('x'),
ylabel('y'),
title ('Input-Output relationship')
out = evalfis(fis, 1.00039)
Warning: Input 1 expects a value in range [-0.2 1], but has a value of 1.00039.
out = 2.5000
% Plot rules
figure(9)
plotrule(fis, Inputs=1.00039)
Note that the membership values of the additional Triangular functions defined at the extremes of the input universe are exactly 1. Refer to the horizontal dashed red line of the fired Rule 4 in the rule inference diagram (Figure 9).

카테고리

Help CenterFile Exchange에서 Fuzzy Inference System Modeling에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by