我正在尝试验证我的 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)
存储从 1 到 5401 的每个时间步的所有状态的每个迭代lsim
并最终得到一个矩阵。我不断收到此错误消息:
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.
非常感谢任何有用的输入。谢谢