【发布时间】:2026-02-15 23:40:01
【问题描述】:
我正在尝试验证我的 RK4 代码并使用状态空间模型来解决相同的系统。我有一个具有初始条件的 14 状态系统,但条件随时间而变化(每次迭代)。我正在尝试制定 A、B、C、D 矩阵并使用 sys 和 lsim 来编译整个时间跨度内所有状态的结果。我正在尝试这样做:
for t=1:1:5401
y1b=whatever
.
.
y14b = whatever
y_0 = vector of ICs
A = (will change with time)
B = (1,14) with mostly zeros and 3 ones
C = ones(14,1)
D = 0
Q = eye(14)
R = eye(1)
k = lqr(A,B,C,D)
A_bar = A - B*k
sys = ss(A_bar,B,C,D)
u = zeros(14,1)
sto(t,14) = lsim(sys,u,t,y_0)
then solve for new y1b-y14b from outside function
end
换句话说,我正在尝试使用sto(t,14) 来存储lsim 的每次迭代,并最终得到一个包含从1 到5401 的每个时间步长的所有状态的矩阵。我不断收到以下错误消息:
Error using DynamicSystem/lsim (line 85)
In time response commands, the time vector must be real, finite, and must contain
monotonically increasing and evenly spaced time samples.
和
Error using DynamicSystem/lsim (line 85)
When simulating the response to a specific input signal, the input data U must be a
matrix with as many rows as samples in the time vector T, and as many columns as
input channels.
非常感谢任何有用的输入。谢谢
【问题讨论】:
标签: matrix matlab state-space control-theory