how to DESIGN ADAPTIVE NEURO-FUZZY INFERENCE SYSTEM (ANFIS)

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

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

Sign in to comment.

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

i am confising,what is y3 and y4 in the above graph is that for my system outputs ? and i need u1 with respect of y1 and u2 with respect y2 graph.
and are just the y-axis labels for reflecting and data displayed in the graph as you can clearly read in the code. No hidden code...
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')
let me tell you shortly , my target is ,to compare LQR and ANFIS result for my system but still now i didnt get satsfied answer with training of ANFIS.
when i run the code what you said above that is, the code below. it says
function dxdt = system(t, x)
Error: Function definition not supported in this context. Create functions in code file.
so please, write all approprate codes for training of ANFIS for my system with its graphs.
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
% 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);
please, tell me how to fix the error above ?
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().
ya you are correct, i simply copied and pasted it. so please tell how to generate data for that state space representation because if input and output data is obtain, then by saving in work space or in a file it is easy for training.i understand already the process but difficult in data generating for my system.
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.

Sign in to comment.

Categories

Tags

Asked:

on 14 Aug 2022

Commented:

on 8 Jan 2024

Community Treasure Hunt

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

Start Hunting!