how to extract data from sys=ss(A,B,C,D) that is , inputs and outputs
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
great do
el 9 de Ag. de 2022
%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 comentarios
Respuesta aceptada
Sam Chak
el 10 de Ag. de 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)
sysc = ss(A-B*K,B,C,D)
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 comentario
Sam Chak
el 10 de Ag. de 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.
Más respuestas (1)
Sam Chak
el 11 de Ag. de 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);
% 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 comentario
Sam Chak
el 12 de Ag. de 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.
Ver también
Categorías
Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!