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

25 visualizzazioni (ultimi 30 giorni)
%State-space representation of the system
A= [-85 250 63];
B= [11 0; 0 11; ];
C=[0 0 1 0 0];
D=[0 0;0 0];
  2 Commenti
Paul
Paul il 9 Ago 2022
Modificato: Paul il 9 Ago 2022
Hi welesh,
Please clarify the question. What exactly is the goal for either the open loop system or the closed loop system (or both)?

Accedi per commentare.

Risposta accettata

Sam Chak
Sam Chak il 10 Ago 2022
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
  1 Commento
Sam Chak
Sam Chak il 10 Ago 2022
In that case, I'd advise you to use the ode45() function to solve the dynamics and generate the data.
If you have access to Simulink, then you can also put your State-space model in the State-space Block, and insert the Matrix K into the Gain Block, provided you understand how to build block diagrams.
You also need to understand what you want to train. If you obtain only the unit step responses data, then I think the trained system only "smart enough" to produce the unit step responses data that converge at around 5 seconds.

Accedi per commentare.

Più risposte (1)

Sam Chak
Sam Chak il 11 Ago 2022
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
  1 Commento
Sam Chak
Sam Chak il 12 Ago 2022
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.

Accedi per commentare.

Categorie

Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by