【问题标题】:Solving State Space Response with Variable A matrix用变量 A 矩阵求解状态空间响应
【发布时间】:2026-02-15 23:40:01
【问题描述】:

我正在尝试验证我的 RK4 代码并使用状态空间模型来解决相同的系统。我有一个具有初始条件的 14 状态系统,但条件随时间而变化(每次迭代)。我正在尝试制定 A、B、C、D 矩阵并使用 syslsim 来编译整个时间跨度内所有状态的结果。我正在尝试这样做:

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


    【解决方案1】:

    要使lsim 起作用,t 必须至少包含 2 个点。

    此外,BC 的大小也会翻转。您有 1 个输入和 1 个输出,因此 u 应该是 lsim 中 t 的长度 1。

    最后,您似乎尝试将所有首字母条件一次放入 lsimy_0 中,您只需要与此迭代相关的部分。

    s = [t-1 t];
    u = [0; 0];
    if t==1
        y0 = y_0;
    else
        y0 = sto(t-1,1:14);
    end
    y = lsim(sys, u, s, y0);
    sto(t,1:14) = y(end,:);
    

    我不确定我是否正确理解了您的问题,但希望对您有所帮助。

    【讨论】:

    • 感谢您的帮助。我试着按照你说的做,但它告诉我初始条件必须与状态相同,即 14。我尝试用 14 步将 s 从 t-1 拉伸到 t,并使 u 的大小也为 14,但它告诉我下标不匹配。有什么想法吗?
    • y_0 的大小是多少?听起来像是14 x 1,在这种情况下,我不明白您要做什么。
    • 这是 y_0 的正确大小,因为它是 14 个状态的初始条件。我正在尝试解决 x_dot = Ax + Bu 和 y=Cx +Du 的问题,其中状态嵌入在 A 矩阵的公式中,但也会随时间变化。这意味着我必须为每个时间步循环 lsim 并每次解析 A 矩阵。最后,我想要一个包含 1-5401 的所有状态值的矩阵,我只关心整数次
    最近更新 更多