getting error in fuzzy inference system & gain block
iam getting error iin FIS system opening even though i kept all files in one folder & its showing below error.
code:
clc; clear; close all;
%% =======================================================
% CHECK & OPEN SIMULINK MODEL CONFIGURATION
% *** PLEASE CHANGE THIS PATH TO YOUR ACTUAL FILE LOCATION ***
%% =======================================================
model = ‘SimFuzzyPID’;
modelPath = ‘D:trials_1611251CP 25 705 (1)finalSimFuzzyPID.slx’;
% Extract folder path and add it to the MATLAB path for file finding
[folderPath, ~, ~] = fileparts(modelPath);
addpath(folderPath);
if ~exist(modelPath, ‘file’)
error(‘SimFuzzyPID.slx NOT FOUND at the specified path. Please check modelPath.’);
end
load_system(model);
open_system(model);
disp([‘Model "’, model, ‘" loaded successfully.’]);
%% =======================================================
% PLANT TRANSFER FUNCTION & DISCRETIZATION
% G(s) = [1250/(s^2 + 50s + 1250)] * [0.57s^2+2.64s+1] * e^(-0.2s)
%% =======================================================
s = tf(‘s’);
G1 = 1250 / (s^2 + 50*s + 1250);
G2 = (0.57*s^2 + 2.64*s + 1);
Delay = exp(-0.2*s);
G = G1 * G2 * Delay;
Ts = 0.01;
Plant = c2d(G, Ts, ‘zoh’);
disp([‘Plant discretized with Ts = ‘, num2str(Ts), ‘s.’]);
%% =======================================================
% PID DESIGN USING pidtune (For initial gains)
%% =======================================================
C0 = pid(1,1,1,’Ts’,Ts,’IF’,’B’,’DF’,’B’);
C = pidtune(Plant, C0);
[Kp, Ki, Kd] = piddata(C);
disp([‘PID Gains: Kp=’, num2str(Kp), ‘, Ki=’, num2str(Ki), ‘, Kd=’, num2str(Kd)]);
%% =======================================================
% FUZZY PID SCALING GAINS
%% =======================================================
% You can tune these manually for better performance if needed
GE = 100; % Input scaling for Error (E)
GCE = GE * (Kp – sqrt(Kp^2 – 4*Ki*Kd)) / (2*Ki); % Input scaling for Change of Error (CE)
GCU = Ki / GE; % Output scaling gain (Ku)
GU = Kd / GCE; % Another output scaling gain (Ku * GCE / Kd, simplified)
disp([‘Calculated Scaling Gains: GE=’, num2str(GE), ‘, GCE=’, num2str(GCE), ‘, GCU=’, num2str(GCU), ‘, GU=’, num2str(GU)]);
%% =======================================================
% BUILD FUZZY FIS (5 MFs Sugeno Structure)
%% =======================================================
FIS = mamfis("FIS","FISType","sugeno");
% — Input 1: Error (E) —
FIS = addInput(FIS,[-100 100],’Name’,’E’);
FIS = addMF(FIS,’E’,"NB","trimf",[-100 -100 -50]); % Negative Big
FIS = addMF(FIS,’E’,"NS","trimf",[-100 -50 0]); % Negative Small
FIS = addMF(FIS,’E’,"Z","trimf",[-50 0 50]); % Zero
FIS = addMF(FIS,’E’,"PS","trimf",[0 50 100]); % Positive Small
FIS = addMF(FIS,’E’,"PB","trimf",[50 100 100]); % Positive Big
% — Input 2: Change of Error (CE) —
FIS = addInput(FIS,[-100 100],’Name’,’CE’);
FIS = addMF(FIS,’CE’,"NB","trimf",[-100 -100 -50]);
FIS = addMF(FIS,’CE’,"NS","trimf",[-100 -50 0]);
FIS = addMF(FIS,’CE’,"Z","trimf",[-50 0 50]);
FIS = addMF(FIS,’CE’,"PS","trimf",[0 50 100]);
FIS = addMF(FIS,’CE’,"PB","trimf",[50 100 100]);
% — Output: Control u (Constants) —
FIS = addOutput(FIS,[-200 200],’Name’,’u’);
FIS = addMF(FIS,’u’,"NB","constant",-200);
FIS = addMF(FIS,’u’,"NS","constant",-100);
FIS = addMF(FIS,’u’,"Z","constant",0);
FIS = addMF(FIS,’u’,"PS","constant",100);
FIS = addMF(FIS,’u’,"PB","constant",200);
% — Rule Base (25 Rules) —
% Mapping: 1=NB, 2=NS, 3=Z, 4=PS, 5=PB
ruleList = [
1 1 1 1 1; 1 2 1 1 1; 1 3 2 1 1; 1 4 2 1 1; 1 5 3 1 1;
2 1 1 1 1; 2 2 2 1 1; 2 3 3 1 1; 2 4 4 1 1; 2 5 4 1 1;
3 1 2 1 1; 3 2 3 1 1; 3 3 3 1 1; 3 4 3 1 1; 3 5 4 1 1;
4 1 2 1 1; 4 2 3 1 1; 4 3 4 1 1; 4 4 4 1 1; 4 5 5 1 1;
5 1 3 1 1; 5 2 4 1 1; 5 3 4 1 1; 5 4 5 1 1; 5 5 5 1 1
];
FIS = addRule(FIS, ruleList);
disp(‘Fuzzy FIS defined with 5 MFs and 25 rules.’);
%% =======================================================
% SAVE FIS TO FILE (Uses the model directory)
%% =======================================================
FIS_FileName = ‘FuzzyPID_Controller.fis’;
fullFilePath = fullfile(folderPath, FIS_FileName);
writeFIS(FIS, fullFilePath);
disp([‘FIS file saved successfully at: ‘, fullFilePath]);
%% =======================================================
% SIMULINK PARAMETER PUSH & SIMULATION
% Push Kp, Ki, Kd, GE, GCE, GCU to the model (assuming blocks are named)
%% =======================================================
% Assuming you have a standard PID block named ‘PID Controller’
% and a Gain block for PID named ‘Kp_Gain’, ‘Ki_Gain’, etc.
% set_param([model, ‘/PID Controller’], ‘P’, num2str(Kp), ‘I’, num2str(Ki), ‘D’, num2str(Kd));
% Assuming you have Gain blocks for the Fuzzy-PID scaling
% set_param([model, ‘/GE_Gain’], ‘Gain’, num2str(GE));
% set_param([model, ‘/GCE_Gain’], ‘Gain’, num2str(GCE));
% set_param([model, ‘/GCU_Gain’], ‘Gain’, num2str(GCU));
simOut = sim(model);
StepPID = simOut.StepPID;
StepFP = simOut.StepFP;
disp(‘Simulation complete.’);
%% =======================================================
% PLOT RESULT: PID vs FUZZY-PID
%% =======================================================
figure;
plot(StepPID.time, StepPID.data,’LineWidth’,2); hold on;
plot(StepFP.time, StepFP.data,’LineWidth’,2);
grid on;
title(‘PID vs Fuzzy-PID Control Performance’);
xlabel(‘Time (s)’);
ylabel(‘Speed Response’);
legend(‘PID’,’Fuzzy-PID’);iam getting error iin FIS system opening even though i kept all files in one folder & its showing below error.
code:
clc; clear; close all;
%% =======================================================
% CHECK & OPEN SIMULINK MODEL CONFIGURATION
% *** PLEASE CHANGE THIS PATH TO YOUR ACTUAL FILE LOCATION ***
%% =======================================================
model = ‘SimFuzzyPID’;
modelPath = ‘D:trials_1611251CP 25 705 (1)finalSimFuzzyPID.slx’;
% Extract folder path and add it to the MATLAB path for file finding
[folderPath, ~, ~] = fileparts(modelPath);
addpath(folderPath);
if ~exist(modelPath, ‘file’)
error(‘SimFuzzyPID.slx NOT FOUND at the specified path. Please check modelPath.’);
end
load_system(model);
open_system(model);
disp([‘Model "’, model, ‘" loaded successfully.’]);
%% =======================================================
% PLANT TRANSFER FUNCTION & DISCRETIZATION
% G(s) = [1250/(s^2 + 50s + 1250)] * [0.57s^2+2.64s+1] * e^(-0.2s)
%% =======================================================
s = tf(‘s’);
G1 = 1250 / (s^2 + 50*s + 1250);
G2 = (0.57*s^2 + 2.64*s + 1);
Delay = exp(-0.2*s);
G = G1 * G2 * Delay;
Ts = 0.01;
Plant = c2d(G, Ts, ‘zoh’);
disp([‘Plant discretized with Ts = ‘, num2str(Ts), ‘s.’]);
%% =======================================================
% PID DESIGN USING pidtune (For initial gains)
%% =======================================================
C0 = pid(1,1,1,’Ts’,Ts,’IF’,’B’,’DF’,’B’);
C = pidtune(Plant, C0);
[Kp, Ki, Kd] = piddata(C);
disp([‘PID Gains: Kp=’, num2str(Kp), ‘, Ki=’, num2str(Ki), ‘, Kd=’, num2str(Kd)]);
%% =======================================================
% FUZZY PID SCALING GAINS
%% =======================================================
% You can tune these manually for better performance if needed
GE = 100; % Input scaling for Error (E)
GCE = GE * (Kp – sqrt(Kp^2 – 4*Ki*Kd)) / (2*Ki); % Input scaling for Change of Error (CE)
GCU = Ki / GE; % Output scaling gain (Ku)
GU = Kd / GCE; % Another output scaling gain (Ku * GCE / Kd, simplified)
disp([‘Calculated Scaling Gains: GE=’, num2str(GE), ‘, GCE=’, num2str(GCE), ‘, GCU=’, num2str(GCU), ‘, GU=’, num2str(GU)]);
%% =======================================================
% BUILD FUZZY FIS (5 MFs Sugeno Structure)
%% =======================================================
FIS = mamfis("FIS","FISType","sugeno");
% — Input 1: Error (E) —
FIS = addInput(FIS,[-100 100],’Name’,’E’);
FIS = addMF(FIS,’E’,"NB","trimf",[-100 -100 -50]); % Negative Big
FIS = addMF(FIS,’E’,"NS","trimf",[-100 -50 0]); % Negative Small
FIS = addMF(FIS,’E’,"Z","trimf",[-50 0 50]); % Zero
FIS = addMF(FIS,’E’,"PS","trimf",[0 50 100]); % Positive Small
FIS = addMF(FIS,’E’,"PB","trimf",[50 100 100]); % Positive Big
% — Input 2: Change of Error (CE) —
FIS = addInput(FIS,[-100 100],’Name’,’CE’);
FIS = addMF(FIS,’CE’,"NB","trimf",[-100 -100 -50]);
FIS = addMF(FIS,’CE’,"NS","trimf",[-100 -50 0]);
FIS = addMF(FIS,’CE’,"Z","trimf",[-50 0 50]);
FIS = addMF(FIS,’CE’,"PS","trimf",[0 50 100]);
FIS = addMF(FIS,’CE’,"PB","trimf",[50 100 100]);
% — Output: Control u (Constants) —
FIS = addOutput(FIS,[-200 200],’Name’,’u’);
FIS = addMF(FIS,’u’,"NB","constant",-200);
FIS = addMF(FIS,’u’,"NS","constant",-100);
FIS = addMF(FIS,’u’,"Z","constant",0);
FIS = addMF(FIS,’u’,"PS","constant",100);
FIS = addMF(FIS,’u’,"PB","constant",200);
% — Rule Base (25 Rules) —
% Mapping: 1=NB, 2=NS, 3=Z, 4=PS, 5=PB
ruleList = [
1 1 1 1 1; 1 2 1 1 1; 1 3 2 1 1; 1 4 2 1 1; 1 5 3 1 1;
2 1 1 1 1; 2 2 2 1 1; 2 3 3 1 1; 2 4 4 1 1; 2 5 4 1 1;
3 1 2 1 1; 3 2 3 1 1; 3 3 3 1 1; 3 4 3 1 1; 3 5 4 1 1;
4 1 2 1 1; 4 2 3 1 1; 4 3 4 1 1; 4 4 4 1 1; 4 5 5 1 1;
5 1 3 1 1; 5 2 4 1 1; 5 3 4 1 1; 5 4 5 1 1; 5 5 5 1 1
];
FIS = addRule(FIS, ruleList);
disp(‘Fuzzy FIS defined with 5 MFs and 25 rules.’);
%% =======================================================
% SAVE FIS TO FILE (Uses the model directory)
%% =======================================================
FIS_FileName = ‘FuzzyPID_Controller.fis’;
fullFilePath = fullfile(folderPath, FIS_FileName);
writeFIS(FIS, fullFilePath);
disp([‘FIS file saved successfully at: ‘, fullFilePath]);
%% =======================================================
% SIMULINK PARAMETER PUSH & SIMULATION
% Push Kp, Ki, Kd, GE, GCE, GCU to the model (assuming blocks are named)
%% =======================================================
% Assuming you have a standard PID block named ‘PID Controller’
% and a Gain block for PID named ‘Kp_Gain’, ‘Ki_Gain’, etc.
% set_param([model, ‘/PID Controller’], ‘P’, num2str(Kp), ‘I’, num2str(Ki), ‘D’, num2str(Kd));
% Assuming you have Gain blocks for the Fuzzy-PID scaling
% set_param([model, ‘/GE_Gain’], ‘Gain’, num2str(GE));
% set_param([model, ‘/GCE_Gain’], ‘Gain’, num2str(GCE));
% set_param([model, ‘/GCU_Gain’], ‘Gain’, num2str(GCU));
simOut = sim(model);
StepPID = simOut.StepPID;
StepFP = simOut.StepFP;
disp(‘Simulation complete.’);
%% =======================================================
% PLOT RESULT: PID vs FUZZY-PID
%% =======================================================
figure;
plot(StepPID.time, StepPID.data,’LineWidth’,2); hold on;
plot(StepFP.time, StepFP.data,’LineWidth’,2);
grid on;
title(‘PID vs Fuzzy-PID Control Performance’);
xlabel(‘Time (s)’);
ylabel(‘Speed Response’);
legend(‘PID’,’Fuzzy-PID’); iam getting error iin FIS system opening even though i kept all files in one folder & its showing below error.
code:
clc; clear; close all;
%% =======================================================
% CHECK & OPEN SIMULINK MODEL CONFIGURATION
% *** PLEASE CHANGE THIS PATH TO YOUR ACTUAL FILE LOCATION ***
%% =======================================================
model = ‘SimFuzzyPID’;
modelPath = ‘D:trials_1611251CP 25 705 (1)finalSimFuzzyPID.slx’;
% Extract folder path and add it to the MATLAB path for file finding
[folderPath, ~, ~] = fileparts(modelPath);
addpath(folderPath);
if ~exist(modelPath, ‘file’)
error(‘SimFuzzyPID.slx NOT FOUND at the specified path. Please check modelPath.’);
end
load_system(model);
open_system(model);
disp([‘Model "’, model, ‘" loaded successfully.’]);
%% =======================================================
% PLANT TRANSFER FUNCTION & DISCRETIZATION
% G(s) = [1250/(s^2 + 50s + 1250)] * [0.57s^2+2.64s+1] * e^(-0.2s)
%% =======================================================
s = tf(‘s’);
G1 = 1250 / (s^2 + 50*s + 1250);
G2 = (0.57*s^2 + 2.64*s + 1);
Delay = exp(-0.2*s);
G = G1 * G2 * Delay;
Ts = 0.01;
Plant = c2d(G, Ts, ‘zoh’);
disp([‘Plant discretized with Ts = ‘, num2str(Ts), ‘s.’]);
%% =======================================================
% PID DESIGN USING pidtune (For initial gains)
%% =======================================================
C0 = pid(1,1,1,’Ts’,Ts,’IF’,’B’,’DF’,’B’);
C = pidtune(Plant, C0);
[Kp, Ki, Kd] = piddata(C);
disp([‘PID Gains: Kp=’, num2str(Kp), ‘, Ki=’, num2str(Ki), ‘, Kd=’, num2str(Kd)]);
%% =======================================================
% FUZZY PID SCALING GAINS
%% =======================================================
% You can tune these manually for better performance if needed
GE = 100; % Input scaling for Error (E)
GCE = GE * (Kp – sqrt(Kp^2 – 4*Ki*Kd)) / (2*Ki); % Input scaling for Change of Error (CE)
GCU = Ki / GE; % Output scaling gain (Ku)
GU = Kd / GCE; % Another output scaling gain (Ku * GCE / Kd, simplified)
disp([‘Calculated Scaling Gains: GE=’, num2str(GE), ‘, GCE=’, num2str(GCE), ‘, GCU=’, num2str(GCU), ‘, GU=’, num2str(GU)]);
%% =======================================================
% BUILD FUZZY FIS (5 MFs Sugeno Structure)
%% =======================================================
FIS = mamfis("FIS","FISType","sugeno");
% — Input 1: Error (E) —
FIS = addInput(FIS,[-100 100],’Name’,’E’);
FIS = addMF(FIS,’E’,"NB","trimf",[-100 -100 -50]); % Negative Big
FIS = addMF(FIS,’E’,"NS","trimf",[-100 -50 0]); % Negative Small
FIS = addMF(FIS,’E’,"Z","trimf",[-50 0 50]); % Zero
FIS = addMF(FIS,’E’,"PS","trimf",[0 50 100]); % Positive Small
FIS = addMF(FIS,’E’,"PB","trimf",[50 100 100]); % Positive Big
% — Input 2: Change of Error (CE) —
FIS = addInput(FIS,[-100 100],’Name’,’CE’);
FIS = addMF(FIS,’CE’,"NB","trimf",[-100 -100 -50]);
FIS = addMF(FIS,’CE’,"NS","trimf",[-100 -50 0]);
FIS = addMF(FIS,’CE’,"Z","trimf",[-50 0 50]);
FIS = addMF(FIS,’CE’,"PS","trimf",[0 50 100]);
FIS = addMF(FIS,’CE’,"PB","trimf",[50 100 100]);
% — Output: Control u (Constants) —
FIS = addOutput(FIS,[-200 200],’Name’,’u’);
FIS = addMF(FIS,’u’,"NB","constant",-200);
FIS = addMF(FIS,’u’,"NS","constant",-100);
FIS = addMF(FIS,’u’,"Z","constant",0);
FIS = addMF(FIS,’u’,"PS","constant",100);
FIS = addMF(FIS,’u’,"PB","constant",200);
% — Rule Base (25 Rules) —
% Mapping: 1=NB, 2=NS, 3=Z, 4=PS, 5=PB
ruleList = [
1 1 1 1 1; 1 2 1 1 1; 1 3 2 1 1; 1 4 2 1 1; 1 5 3 1 1;
2 1 1 1 1; 2 2 2 1 1; 2 3 3 1 1; 2 4 4 1 1; 2 5 4 1 1;
3 1 2 1 1; 3 2 3 1 1; 3 3 3 1 1; 3 4 3 1 1; 3 5 4 1 1;
4 1 2 1 1; 4 2 3 1 1; 4 3 4 1 1; 4 4 4 1 1; 4 5 5 1 1;
5 1 3 1 1; 5 2 4 1 1; 5 3 4 1 1; 5 4 5 1 1; 5 5 5 1 1
];
FIS = addRule(FIS, ruleList);
disp(‘Fuzzy FIS defined with 5 MFs and 25 rules.’);
%% =======================================================
% SAVE FIS TO FILE (Uses the model directory)
%% =======================================================
FIS_FileName = ‘FuzzyPID_Controller.fis’;
fullFilePath = fullfile(folderPath, FIS_FileName);
writeFIS(FIS, fullFilePath);
disp([‘FIS file saved successfully at: ‘, fullFilePath]);
%% =======================================================
% SIMULINK PARAMETER PUSH & SIMULATION
% Push Kp, Ki, Kd, GE, GCE, GCU to the model (assuming blocks are named)
%% =======================================================
% Assuming you have a standard PID block named ‘PID Controller’
% and a Gain block for PID named ‘Kp_Gain’, ‘Ki_Gain’, etc.
% set_param([model, ‘/PID Controller’], ‘P’, num2str(Kp), ‘I’, num2str(Ki), ‘D’, num2str(Kd));
% Assuming you have Gain blocks for the Fuzzy-PID scaling
% set_param([model, ‘/GE_Gain’], ‘Gain’, num2str(GE));
% set_param([model, ‘/GCE_Gain’], ‘Gain’, num2str(GCE));
% set_param([model, ‘/GCU_Gain’], ‘Gain’, num2str(GCU));
simOut = sim(model);
StepPID = simOut.StepPID;
StepFP = simOut.StepFP;
disp(‘Simulation complete.’);
%% =======================================================
% PLOT RESULT: PID vs FUZZY-PID
%% =======================================================
figure;
plot(StepPID.time, StepPID.data,’LineWidth’,2); hold on;
plot(StepFP.time, StepFP.data,’LineWidth’,2);
grid on;
title(‘PID vs Fuzzy-PID Control Performance’);
xlabel(‘Time (s)’);
ylabel(‘Speed Response’);
legend(‘PID’,’Fuzzy-PID’); fuzzy logic inference error MATLAB Answers — New Questions









