how to extract data from sys=ss(A,B,C,D) that is , inputs and outputs

์กฐํšŒ ์ˆ˜: 10(์ตœ๊ทผ 30์ผ)
welesh beyene
welesh beyene 2022๋…„ 8์›” 9์ผ
๋Œ“๊ธ€: Sam Chak 2022๋…„ 8์›” 12์ผ
%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,'statename',states,'inputname',inputs,'outputname',outputs);
%Open-Loop Step Response
step(sys)
title('Open-Loop Step Response')
% 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
%LQR design
%manual tuning of Q and R
%Fixed R=1 search for Q
figure(1)
for Qi=[0.1,1,10,100,1000]
Q=diag([Qi,Qi,Qi,Qi,10*Qi,10*Qi]);
R=10*eye(2);%[10,0;0,10]
[K]=lqr(A,B,Q,R);
dt=0.01;
t=0:dt:10;
step(ss(A-B*K,B,C,D),t);
hold on
end
legend('Qi=0.1','Qi=1','Qi=10','Qi=100','Qi=1000');
title('step response of LQR with different weighting factors')
%Fixed Q=0.01 serach for R
figure(2)
Q=diag([0.1,0.1,0.1,0.1,1,1]);
for Ri=[0.01,0.1,1,10]
R=diag([Ri,Ri]);
[K]=lqr(A,B,Q,R);
dt=0.01;
t=0:dt:10;
step(ss(A-B*K,B,C,D),t);
hold on
end
legend('Ri=0.01','Ri=0.1','Ri=1','Ri=10');
%System well stabilized at Q=0.01 and R=100
figure(3)
Q=diag([0.1,0.1,0.1,0.1,1,1]);
R=diag([10,10]);
K=lqr(A,B,Q,R);
step(ss(A-B*K,B,C,D));
  ๋Œ“๊ธ€ ์ˆ˜: 5
welesh beyene
welesh beyene 2022๋…„ 8์›” 11์ผ
since i have two inputs and outputs i need those value inorder to use for train of adaptive neuro fuzzy inference system(ANFIS) so, how i can find those inputs and output ?

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Sam Chak
Sam Chak 2022๋…„ 8์›” 10์ผ
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];
Q = diag([0.1, 0.1, 0.1, 0.1, 1, 1]);
R = diag([10, 10]);
K = lqr(A, B, Q, R)
K = 2ร—6
0.0269 -0.0147 2.0369 -0.0147 1.2296 0.6755 -0.0147 0.0269 -0.0147 2.0369 0.6755 1.2296
sysc = ss(A-B*K,B,C,D)
sysc = A = x1 x2 x3 x4 x5 x6 x1 -308.1 4.4 -611.1 4.4 -368.9 -202.7 x2 4.4 -308.1 4.4 -611.1 -202.7 -368.9 x3 0 0 0 0 1 0 x4 0 0 0 0 0 1 x5 10.72 -9.565 10.72 -9.565 0 0 x6 -9.565 10.72 -9.565 10.72 0 0 B = u1 u2 x1 300 0 x2 0 300 x3 0 0 x4 0 0 x5 0 0 x6 0 0 C = x1 x2 x3 x4 x5 x6 y1 0 0 1 0 0 0 y2 0 0 0 1 0 0 D = u1 u2 y1 0 0 y2 0 0 Continuous-time state-space model.
You can probably extract the outputs {} caused by the inputs {} like this:
[y, t] = step(sysc, 10);
for j = 1:4
subplot(2,2,j)
plot(t, y(:,j)), grid on, xlabel('t'), ylim([-0.3 1.1])
end
  ๋Œ“๊ธ€ ์ˆ˜: 3
welesh beyene
welesh beyene 2022๋…„ 8์›” 10์ผ
what is ode45() function ? and i want to use the inputs and output data for training of adaptive neuro fuzzy inference system(ANFIS)

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€(1๊ฐœ)

Sam Chak
Sam Chak 2022๋…„ 8์›” 11์ผ
Let's try this simple state-space model and generate the data using ode45() function (click on the link):
If the input is designed as , the feedback closed-loop system becomes:
I'm referring to some examples in anfis() documentation. If you find the demo and MATLAB code helpful, please consider voting ๐Ÿ‘ the Answer.
[t, y] = ode45(@system, [0 10], [1; 0]);
plot(t, y), grid on, xlabel('t'), ylabel('\bf{y}(t)'), legend('y_1', 'y_2')
% organizing the data
out1 = y(:,1); % position signal
out2 = y(:,2); % velocity signal
in_u = - y(:,1) - 2*y(:,2); % force signal
FISin = out1; % input to the FIS that we want to train
FISout = in_u; % output to the FIS that we want to train
data1 = [FISin FISout];
% setting up the ANFIS
genOpt = genfisOptions('GridPartition');
genOpt.NumMembershipFunctions = 3;
genOpt.InputMembershipFunctionType = 'gaussmf';
inFIS = genfis(data1(:,1), data1(:,2), genOpt);
opt = anfisOptions('InitialFIS', inFIS, 'EpochNumber', 60);
fis = anfis(data1, opt);
ANFIS info: Number of nodes: 16 Number of linear parameters: 6 Number of nonlinear parameters: 6 Total number of parameters: 12 Number of training data pairs: 73 Number of checking data pairs: 0 Number of fuzzy rules: 3 Start training ANFIS ... 1 0.0559898 2 0.0548279 3 0.0537759 4 0.0528129 Step size increases to 0.011000 after epoch 5. 5 0.0519196 6 0.0510792 7 0.0502002 8 0.0493556 Step size increases to 0.012100 after epoch 9. 9 0.0485363 10 0.0477374 11 0.0468815 12 0.0460528 Step size increases to 0.013310 after epoch 13. 13 0.045258 14 0.0445051 15 0.0437341 16 0.0430297 Step size increases to 0.014641 after epoch 17. 17 0.0423943 18 0.0418257 19 0.041271 20 0.0407799 Step size increases to 0.016105 after epoch 21. 21 0.0403412 22 0.0399454 23 0.0395517 24 0.0391966 Step size increases to 0.017716 after epoch 25. 25 0.0388743 26 0.0385768 27 0.0382683 28 0.037974 Step size increases to 0.019487 after epoch 29. 29 0.0376911 30 0.0374207 31 0.0371399 32 0.0368765 Step size increases to 0.021436 after epoch 33. 33 0.0366245 34 0.036376 35 0.0360996 36 0.0358142 Step size increases to 0.023579 after epoch 37. 37 0.0355162 38 0.0352057 39 0.0348567 40 0.0345119 Step size increases to 0.025937 after epoch 41. 41 0.0341598 42 0.033809 43 0.0333839 44 0.0335596 45 0.0329597 46 0.0332002 Step size decreases to 0.023344 after epoch 47. 47 0.0323918 48 0.0326266 49 0.0317615 50 0.0315423 51 0.0312428 Step size increases to 0.025678 after epoch 52. 52 0.03111 53 0.0302846 54 0.0299535 55 0.0288002 Step size increases to 0.028246 after epoch 56. 56 0.0276869 57 0.0260923 58 0.0241319 59 0.0224591 Step size increases to 0.031070 after epoch 60. 60 0.0212941 Designated epoch number reached. ANFIS training completed at epoch 60. Minimal training RMSE = 0.0212941
% plotting the results
u = data1(:,1);
anfisOutput = evalfis(fis, u);
plot(u, data1(:,2), '*r', u, anfisOutput,'.b')
grid on, xlabel('y_1'), ylabel('u'),
legend('Training Data', 'ANFIS Output', 'Location', 'best')
function dydt = system(t, y)
u = - y(1) - 2*y(2); % input
dydt = [y(2); % state #1 differential equation
u]; % state #2 differential equation
end
  ๋Œ“๊ธ€ ์ˆ˜: 3
Sam Chak
Sam Chak 2022๋…„ 8์›” 12์ผ
I don't know what exactly you want to train because you just mentioned that there are two inputs and two outputs. Moreover, what is the scientific motivation behind the training activity?
You have designed the LQR to make the system to behave as desired.
Do you think that training something would improve the performance? It would be helpful you can provide a little background.
I strongly advise you to write/provide the mathematical equation for the inputs and . You are going need them in your ode45() code to generate the data points for the inputs and outputs.
This is just my example to generate the input u based on the equation that I defined:
[t, y] = ode45(@system, [0 10], [1; 0]);
out1 = y(:,1); % generate output 1
out2 = y(:,2); % generate output 2
in_u = - y(:,1) - 2*y(:,2); % generate input
% System dynamics
function dydt = system(t, y)
u = - y(1) - 2*y(2); % input
dydt = [y(2); % state #1 differential equation
u]; % state #2 differential equation
end
Since you have two inputs, I expect there are two equations.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

Community Treasure Hunt

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

Start Hunting!

Translated by