How to generate 2-D Lookup Table data for a 3-Output Fuzzy Logic System

조회 수: 5 (최근 30일)
Aditya Gandhi
Aditya Gandhi 2021년 8월 3일
답변: Sam Chak 2025년 4월 26일
I want design a look up table for fuzzy logic which has 2 inputs and 3 outputs. I referred to help on mathworks however its for 2 inputs and 1 output. Please refer to attached image.
Please suggest a way to create look up table for fuzzy logic using 2 inputs and 3 outputs.
  댓글 수: 1
Venkateshkumar Mohan
Venkateshkumar Mohan 2021년 9월 12일
you can do this. first open fuzzy tool box and select edit and go to add variable ( input and output )

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

답변 (1개)

Sam Chak
Sam Chak 2025년 4월 26일
The code in your image is flawed, as it should have used 'LookUpTableData(j,i)' instead of 'LookUpTableData(i,j)'. This mistake went unnoticed for many years because the ranges of the Error (E) and the Change in Error (CE) are identical, and the design of the control surface is linear and symmetrical.
The solution from a similar question also uses the evalfis() function to generate the 2-D lookup table data for a 2-input, 1-output Fuzzy PID controller using a for-loop indexing approach. For users who are unfamiliar with looping and indexing, the following solution can directly generate the 2-D lookup table data for a 2-input, 3-output fuzzy system using the gensurf() function. The desired output and the number of grid points for the 2-D table can be selected via the 'OutputIndex' and 'NumGridPoints' options in the gensurfOptions() function.
%% World's simplest Fuzzy PID Gain Scheduler (not a Controller yet!)
fis = sugfis;
% Fuzzy Input E
fis = addInput(fis, [-1 +1], 'Name', 'E');
fis = addMF(fis, 'E', 'trapmf', [-2 -2 +2 +2], 'Name', 'All-Encompassing');
% Fuzzy Input CE
fis = addInput(fis, [-1 +1], 'Name', 'CE');
fis = addMF(fis, 'CE', 'trapmf', [-2 -2 +2 +2], 'Name', 'All-Encompassing');
% Fuzzy Output 1 Kp
fis = addOutput(fis, [0 2], 'Name', 'Kp');
kp = 1; % proportional gain
fis = addMF(fis, 'Kp', 'constant', kp, 'Name', 'kp_gain');
% Fuzzy Output 2 Ki
fis = addOutput(fis, [2 4], 'Name', 'Ki');
ki = 2; % integral gain
fis = addMF(fis, 'Ki', 'constant', ki, 'Name', 'ki_gain');
% Fuzzy Output 3 Kd
fis = addOutput(fis, [1 3], 'Name', 'Kd');
kd = 3; % derivative gain
fis = addMF(fis, 'Kd', 'constant', kd, 'Name', 'kd_gain');
% Fuzzy Rule
fis = addRule(fis, "If E is All-Encompassing and CE is All-Encompassing then Kp is kp_gain, Ki is ki_gain, Kd is kd_gain");
%% Testing evalfis outputs
e = (-1:0.5:1)';
ce = e;
K = evalfis(fis, [e ce])
K = 5×3
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
%% PLot results
figure
subplot(211)
plotmf(fis, 'input', 1), grid on, ylim([-0.2, 1.2]),
xlabel('Error'), title('Only one membership function of E')
subplot(212)
plotmf(fis, 'input', 2), grid on, ylim([-0.2, 1.2]),
xlabel('Change in Error'), title('Only one membership function of CE')
%% Generate the 2-D lookup table data using gensurf
opt1 = gensurfOptions('OutputIndex', 1, 'NumGridPoints', 51);
[E, CE, Kp] = gensurf(fis, opt1); % <-- generate 2-D Lookup Table data for Kp
figure
surf(E, CE, Kp);
xlabel('Error'), ylabel('Change in Error'), zlabel('Kp')
title ('Fuzzy Kp Gain Surface')
opt2 = gensurfOptions('OutputIndex', 2, 'NumGridPoints', 51);
[E, CE, Ki] = gensurf(fis, opt2); % <-- generate 2-D Lookup Table data for Ki
figure
surf(E, CE, Ki);
xlabel('Error'), ylabel('Change in Error'), zlabel('Ki')
title ('Fuzzy Ki Gain Surface')
opt3 = gensurfOptions('OutputIndex', 3, 'NumGridPoints', 51);
[E, CE, Kd] = gensurf(fis, opt3); % <-- generate 2-D Lookup Table data for Kd
figure
surf(E, CE, Kd);
xlabel('Error'), ylabel('Change in Error'), zlabel('Kd')
title ('Fuzzy Kd Gain Surface')

카테고리

Help CenterFile Exchange에서 Fuzzy Logic in Simulink에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by