how to DESIGN ADAPTIVE NEURO-FUZZY INFERENCE SYSTEM (ANFIS)
Show older comments
if my state space representation is given by:
%State-space representation of the system
A= [-23.5 120 32];
B= [18 0; 0 500; ];
C=[0 0 1 0 0 0];
D=[0 0;0 0];
1 Comment
Sam Chak
on 8 Jan 2024
It appears that there may have been an accident. I think the subsequent statement represents the initial description of the question provided by @welesh beyene:
------------------------------------------
if my state space representation is given by:
%State-space representation of the system
A= [-300 0 0 0 0 0; 0 -300 0 0 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 10.7206 -9.5648 10.7206 -9.5648 0 0; -9.5648 10.7206 -9.5648 10.7206 0 0];
B= [300 0; 0 300; 0 0; 0 0; 0 0; 0 0];
C=[0 0 1 0 0 0;0 0 0 1 0 0];
D=[0 0;0 0];
%states={'iA' 'iB' 'XA' 'XB' 'XdotA' 'XdotB'};
%inputs={'UA' 'UB'};
%outputs = {'YA' 'YB'};
sys=ss(A,B,C,D)
%Open-Loop Step Response
step(sys)
title('Open-Loop Step Response')
figure(1)
% check the controllability of the system
Ct=ctrb(A,B);
rank(Ct)
if rank(Ct)<rank(A);
disp('the system is not controllable')
else
disp('the system is controllable')
end
% check the observability of the system
Ob=obsv(A,C);
rank(Ob)
if rank(Ob)<rank(A);
disp('the system is not observable')
else
disp('the system is observable')
end
Answers (1)
Have already recommended you to use ode45() function. Links and Examples were given previously.
This should generate the inputs–outputs that you need to train the ANFIS:
[t, x] = ode45(@system, [0 10], [0; 0; 0; 0; 0; 0]);
figure(1)
subplot(211), plot(t, x(:,3)), grid on, xlabel('t'), ylabel('y_3')
subplot(212), plot(t, x(:,4)), grid on, xlabel('t'), ylabel('y_4')
A = [-300 0 0 0 0 0; 0 -300 0 0 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 10.7206 -9.5648 10.7206 -9.5648 0 0; -9.5648 10.7206 -9.5648 10.7206 0 0];
B = [300 0; 0 300; 0 0; 0 0; 0 0; 0 0];
Q = diag([0.1, 0.1, 0.1, 0.1, 1, 1]);
R = diag([10, 10]);
K = lqr(A, B, Q, R);
u1 = - K(1,:)*x' + 1;
u2 = - K(2,:)*x' + 1;
data1 = [x u1']; % Data Set 1
data2 = [x u2']; % Data Set 2
figure(2)
subplot(211), plot(t, u1), grid on, xlabel('t'), ylabel('u_1')
subplot(212), plot(t, u2), grid on, xlabel('t'), ylabel('u_2')
% 6th-order system
function dxdt = system(t, x)
A = [-300 0 0 0 0 0; 0 -300 0 0 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 10.7206 -9.5648 10.7206 -9.5648 0 0; -9.5648 10.7206 -9.5648 10.7206 0 0];
B = [300 0; 0 300; 0 0; 0 0; 0 0; 0 0];
Q = diag([0.1, 0.1, 0.1, 0.1, 1, 1]);
R = diag([10, 10]);
K = lqr(A, B, Q, R);
r = [1; 1];
u = - K*x + r;
dxdt = A*x + B*u;
end
Because the following code for ANFIS training takes more 55 seconds, it won't work in the forum.
% setting up the ANFIS
genOpt = genfisOptions('GridPartition');
genOpt.NumMembershipFunctions = 3;
genOpt.InputMembershipFunctionType = 'gaussmf';
inFIS1 = genfis(data1(:,1:6), data1(:,7), genOpt);
opt1 = anfisOptions('InitialFIS', inFIS1, 'EpochNumber', 60);
fis1 = anfis(data1, opt1);
inFIS2 = genfis(data2(:,1:6), data2(:,7), genOpt);
opt2 = anfisOptions('InitialFIS', inFIS2, 'EpochNumber', 60);
fis2 = anfis(data2, opt2);
7 Comments
great do
on 15 Aug 2022
If you want to name it
, for naming sake, you can intuitively do this:
ylabel('y_1') % x3(t) data
If you mean
for
and
for
, then you can extract the data:
y1 = x(:,1);
y2 = x(:,2);
Does this solve your problem?
No change on
and
. With that, you can plot the graphs for
vs.
and
vs.
:
subplot(211), plot(y1, u1), grid on, xlabel('y1'), ylabel('u1')
subplot(212), plot(y2, u2), grid on, xlabel('y2'), ylabel('u2')
Sam Chak
on 17 Aug 2022
Hi @welesh beyene, I guess you copied/pasted the code (everything in 1 shot) in the MATLAB Command Window? Please clarify.
Actually you can do this in two (2) stages.
The first stage, you solve the ODE and generate the desired data where you can see on the data are temporarily stored in the MATLAB Workspace.
In the second stage, you setup the genfis according to your wish and train using anfis.
As an expert of your own STATE-SPACE system, you must fully understand what you are doing in the 1st stage (before the training stage) and what specific data you need in 2nd stage (ANFIS training).
Please list out all data available in Stage 1.
Please list out the data required for Stage 2.
I'd suggest you quickly go through this 2-hour free MATLAB Onramp course so that you can understand the process better when we suggest you do this and that. I skip the basics like create a function m-file, put this in <NAME> Folder, call this function().
great do
on 18 Aug 2022
Sam Chak
on 18 Aug 2022
Simulink is probably suitable for you to build the State Space model and generate the needed data, where you can send them to the Workspace.
Please show the Simulink model first.
Categories
Find more on Fuzzy Logic in Simulink 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!
