A-B-C-D

State Space

Continuous
运行在线示例 免费 · 无需注册 · 直接在浏览器中运行

StateSpace 模块实现采用矩阵状态空间形式表述的通用连续时间线性定常(LTI)动态系统。通过内部状态向量(x\mathbf{x})、控制输入向量(u\mathbf{u})与测量输出向量(y\mathbf{y})对物理受控对象进行统一建模,它是现代控制理论、多变量(MIMO)系统设计、卡尔曼滤波、线性二次型调节器(LQR)以及结构模态分析的基础基石。模块全面支持标准 MATLAB/矩阵语法(分号分隔行),原生支持多输入多输出,并通过 WebAssembly 高阶数值求解器解算连续状态轨迹。

数学模型

连续时间状态空间系统由一阶向量微分状态方程与代数测量方程共同定义:

x˙(t)=Ax(t)+Bu(t)y(t)=Cx(t)+Du(t)\begin{aligned} \dot{\mathbf{x}}(t) &= \mathbf{A}\mathbf{x}(t) + \mathbf{B}\mathbf{u}(t) \\ \mathbf{y}(t) &= \mathbf{C}\mathbf{x}(t) + \mathbf{D}\mathbf{u}(t) \end{aligned}

其中:

  • x(t)∈Rn\mathbf{x}(t) \in \mathbb{R}^n 为 nn 维内部状态向量
  • u(t)∈Rm\mathbf{u}(t) \in \mathbb{R}^m 为 mm 维外部输入向量
  • y(t)∈Rp\mathbf{y}(t) \in \mathbb{R}^p 为 pp 维测量输出向量
  • A∈Rn×n\mathbf{A} \in \mathbb{R}^{n \times n} 为系统状态转移矩阵
  • B∈Rn×m\mathbf{B} \in \mathbb{R}^{n \times m} 为输入控制矩阵
  • C∈Rp×n\mathbf{C} \in \mathbb{R}^{p \times n} 为输出观测矩阵
  • D∈Rp×m\mathbf{D} \in \mathbb{R}^{p \times m} 为直接前馈传递矩阵

矩阵 A\mathbf{A} 的特征值决定了系统的特征极点:

det⁡(λI−A)=0\det(\lambda \mathbf{I} - \mathbf{A}) = 0

系统渐近稳定的充要条件是矩阵 A\mathbf{A} 的所有特征值均具有严格负实部(Re⁡(λi)<0\operatorname{Re}(\lambda_i) < 0)。在频域中,对应的等效 p×mp \times m 传递函数矩阵计算如下:

G(s)=C(sI−A)−1B+D\mathbf{G}(s) = \mathbf{C}(s\mathbf{I} - \mathbf{A})^{-1}\mathbf{B} + \mathbf{D}

输入与输出

Direction ID Label 类型 Status
→ In u Input(s) number Required
→ In reset Reset number Optional
← Out y Output(s) number Output

参数

参数 Label 类型 默认值 描述
A A Matrix (state) matrix -1
B B Matrix (input) matrix 1
C C Matrix (output) matrix 1
D D Matrix (feedthrough) vector 0
initialState Initial State (comma-sep) vector 0

使用示例

示例 1:小车倒立摆线性化状态空间模型

在倒立摆直立不稳定平衡点附近对其进行线性化建模,状态向量为 x=[x,x˙,θ,θ˙]T\mathbf{x} = [x, \dot{x}, \theta, \dot{\theta}]^T。配置 A = "0 1 0 0; 0 -0.1 2.5 0; 0 0 0 1; 0 -0.2 28.5 0", B = "0; 1.5; 0; 3.0", C = "1 0 0 0; 0 0 1 0"(同时测量小车位置与摆杆角位移),D = "0; 0", initialState = "0, 0, 0.05, 0"。由此可直接检验状态反馈镇定控制器(u=−Kxu = -\mathbf{K}\mathbf{x})在 0.05 rad0.05\text{ rad} 初始倾角下的闭环控制效果。

示例 2:双惯量扭转弹性驱动轴动力学仿真

建模电机与负载之间的弹性转轴扭转振荡,状态变量分别取电机转速、负载转速及转轴相对扭角。设置 A = "-0.2 0 -5; 0 -0.1 5; 1 -1 0", B = "1; 0; 0", C = "0 1 0", D = "0"。该模型精准复现了电机启动阶跃过程中轴系的扭转共振衰减与动态扭矩传递。

说明与最佳实践

  • 矩阵维度严格匹配规则:各矩阵维度必须在代数上完全自洽:若 A\mathbf{A} 为 n×nn \times n,则 B\mathbf{B} 必须为 n×mn \times m,C\mathbf{C} 为 p×np \times n,D\mathbf{D} 为 p×mp \times m。维度不一致将在编译时触发错误。
  • 多变量 (MIMO) 自动拓扑自适应:模块输入端口数自动根据 B\mathbf{B} 的列数扩展,输出端口数自动匹配 C\mathbf{C} 的行数。
  • 高阶刚性 ODE 求解器适配:在底座 Rust 内核中通过 RK4、RK45 显式求解器以及针对宽频刚性矩阵的 TR-BDF2 隐式求解器进行求解,确保高度数值稳定性。
  • 外部复位端口能力:向可选的 reset 端口输入有效正电平信号时,状态向量 x(t)\mathbf{x}(t) 将立即重置为 initialState 中定义的初始状态。

常见工程问题解答 (FAQ)

Q: How to select weighting matrices Q and R for Linear Quadratic Regulator (LQR)?

Use Bryson's Rule as an engineering baseline: set diagonal elements to Qii=1(xi,max⁡)2Q_{ii} = \frac{1}{(x_{i,\max})^2} and Rjj=1(uj,max⁡)2R_{jj} = \frac{1}{(u_{j,\max})^2}, where xi,max⁡x_{i,\max} is the maximum acceptable deviation for state ii and uj,max⁡u_{j,\max} is the maximum actuator excursion. This normalizes all state penalties and control efforts to non-dimensional units, allowing intuitive trade-offs between response speed and actuator effort.

Q: How does State-Space compare to Transfer Function representation?

Transfer functions G(s)=Y(s)/U(s)G(s) = Y(s)/U(s) describe single-input single-output (SISO) input-output dynamics under zero initial conditions, hiding internal plant dynamics. State-Space models (x˙=Ax+Bu,y=Cx+Du\dot{x} = Ax + Bu, y = Cx + Du) naturally handle multi-input multi-output (MIMO) systems, non-zero initial conditions, and internal observability and controllability structures.

相关模块

  • TransferFunction: 单输入单输出(SISO)多项式传递函数 B(s)/A(s)B(s)/A(s)。
  • ZeroPole: 零极点增益因式分解形式 K∏(s−zi)/∏(s−pj)K \prod(s - z_i) / \prod(s - p_j)。
  • Integrator: 连续时间单状态 1/s1/s 动态积分器。
  • SecondOrderSystem: 标准二阶连续振荡器环节。