Azzera filtri
Azzera filtri

Is the state variable x a column vector or a row vector?

4 visualizzazioni (ultimi 30 giorni)
In a state space equation such as xdot=Ax+Bu, if the system has only two state variables, x1 and x2, shouldn't the x matrix be just a 2*1 matrix? Suppose I control the system by means of an LQR linear controller and get the corresponding results for the state variables x1 and x2, at this point I want to represent them by means of an image. At this point I just want to know the representation of x1 in the image, is it correct to use the plot(t,x(:,1)); statement. If the plotting is correct at this point, but x(:,1) is queried in the help as referring to the elements of all rows in the first column of the matrix, this suggests that the value of x1 is stored in the first column of the x matrix, but as stated at the beginning the x matrix should be a 2 row, 1 column matrix.
About why the plot(t,x(:,1)); statement is used to get the image of x1 is something I can't understand at the moment.
Hope someone can help me with this query, thanks a lot!!!!
Translated with www.DeepL.com/Translator (free version)
clc;clear;close all;
%% 定义参数
g=10;
d=1;
%% 定义矩阵
A=[0 1;g/d 0];
B=[0;1];
C = [1, 0];
D = 0;
%% 建立状态空间方程表达式
sys = ss(A,B,C,D);
%% 定义初始状态
z0=[pi/20;0];
%% 定义权重系数,求K
q1=[100 0;0 1];
r1=1;
[K1, z, l] = lqr (sys, q1, r1);
q2=[1 0;0 100];
r2=1;
[K2, z, l] = lqr (sys, q2, r2);
q3=[1 0;0 1];
r3=100;
[K3, z, l] = lqr (sys, q3, r3);
%% 定义闭环系统
sys_cl1=ss(A-B*K1,[0;0],C,D);
sys_cl2=ss(A-B*K2,[0;0],C,D);
sys_cl3=ss(A-B*K3,[0;0],C,D);
%% 仿真
%% 对初始条件的响应
t=0:0.01:5;
[y1,t,z1]=initial(sys_cl1,z0,t);
[y2,t,z2]=initial(sys_cl2,z0,t);
[y3,t,z3]=initial(sys_cl3,z0,t);
%% 绘图
%% 状态变量1
subplot(3,1,1);
plot(t,z1(:,1));
hold on;
plot(t,z2(:,1));
hold on;
plot(t,z3(:,1));
legend('z1_1','z1_2','z1_3');
grid on;
hold off;
%% 状态变量2
subplot(3,1,2);
plot(t,z1(:,2));
hold on;
plot(t,z2(:,2));
hold on;
plot(t,z3(:,2));
legend('z2_1','z2_2','z2_3');
grid on;
hold off;
%% 系统输入
subplot(3,1,3);
plot(t,-K1*z1');
hold on;
plot(t,-K2*z3');
hold on;
plot(t,-K3*z3');
legend('u_1','u_2','u_3');
grid on;
hold off;

Risposta accettata

Shivani
Shivani il 14 Mag 2024
Hello @思雨,
For a system with two state variables, the state vector should be a 2x1 matrix (or column vector) in the context of the state-space equation. However, when we simulate or solve these equations over time the convention changes slightly.
When we simulate the system over a time vector t, MATLAB constructs the solution matrix z in a way that each row represents the state vector at a specific point in time. Therefore, for a system with two state variables, the solution matrix z will have two columns. Each row corresponds to a different time instance, as specified by a time vector t.
The code snippet provided in the question calculates 'z1' across 501 time periods, as 't' is represented by a 501x1 dimensional vector. The sizes of ‘z1’ and ‘t’ can be verified by running the following command:
size(z1)
size(t)
This is why the command plot(t,z1(:,1));, is correctly addressing the first state variable z1’ over all the time points. z1(:,1) selects all rows (time points) of the first column ‘z1’, which is the data required for plotting z1 against time t.
Hope this helps!

Più risposte (0)

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by