matrix - 使用 Modelica integralExp 函数的 LTI 状态空间模型离散化不起作用
问题描述
我需要在 OpenModelica (OMEdit) 中对连续 LTI 状态空间模型执行 ZOH 离散化。我尝试了两种方法:
- 使用矩阵指数 ( Matrices.exp函数) 计算离散化 A 矩阵 (A d ) 并随后计算离散化 B 矩阵 (B d ) 以下方程:B d = A -1 (A d - I) B,其中I是恒等式矩阵; 这个代数方程可以通过直接计算矩阵求逆(Matrices.inv函数)来求解,或者更有效地,通过使用Matrices.solve2函数求解B d矩阵:,从而避免计算矩阵求逆。但是,在这两种情况下A
Bd = Matrices.solve2(A,(Ad-identity(2)))
矩阵必须是可逆的,通常(并且经常)不成立。 - 使用Matrices.integralExp函数,它应该返回两个离散矩阵(A d,B d)并且应该适用于一般矩阵A,无论是可逆的还是奇异的;但是,此功能对我不起作用-它返回错误消息:“令牌附近没有可行的替代方案:( ”。
出于演示目的,我附上了这两种方法的代码。状态空间模型表示一个非常简单的线性化摆的二阶系统,其长度为 1 m,质量为 1 kg,重力加速度为 9.81 m/s 2。离散化的采样时间为 0.1 s。第一个代码工作正常(在这种特殊情况下A是可逆的),但第二个代码不能。有人知道我在做什么错吗?我会很感激任何建议。
方法#1:
model ssDiscretization
import Modelica.Math.Matrices;
// Continuous LTI state-space model of pendulum: L=1, m=1, g=9.81
Real A[2,2] = [0, 1; -9.81, 0] "system matrix";
Real B[2,1] = [0; 1] "input matrix";
// Discretization with sampling time 0.1 s
Real Ad[2,2] = Matrices.exp(A,0.1) "T = 0.1 s";
Real Bd[2,1] = Matrices.inv(A)*(Ad - identity(2))*B;
end ssDiscretization;
方法#2:
model ssDiscretization
import Modelica.Math.Matrices;
// Continuous LTI state-space model of pendulum: L=1, m=1, g=9.81
Real A[2,2] = [0, 1; -9.81, 0] "system matrix";
Real B[2,1] = [0; 1] "input matrix";
// Discretization with sampling time 0.1 s
Real Ad[2,2];
Real Bd[2,1];
(Ad,Bd) = Matrices.integralExp(A,B,0.1) "T = 0.1 s";
end ssDiscretization;
奥利弗
解决方案
您忘记了示例 2 中的 equation 关键字。它仍然无法在 OpenModelica 中工作,因为该函数中的别名似乎存在问题,na=size(A,1)
但您可以轻松修复源代码以使其正常工作。
model ssDiscretization
import Modelica.Math.Matrices;
// Continuous LTI state-space model of pendulum: L=1, m=1, g=9.81
Real A[2,2] = [0, 1; -9.81, 0] "system matrix";
Real B[2,1] = [0; 1] "input matrix";
// Discretization with sampling time 0.1 s
Real Ad[2,2];
Real Bd[2,1];
equation // This was missing
(Ad,Bd) = Matrices.integralExp(A,B,0.1) "T = 0.1 s";
end ssDiscretization;
推荐阅读
- c++ - CMake ToolChain 的常用工具
- java - 如何为 Java Executor 的 runnable 提供参数?
- javascript - 在javascript中(ajax成功)在富文本区域中显示数据?
- pyqt5 - How can I add Icons to a QListWidget
- sql - 计算预订系统中每个时段的预订数量
- python - python - 如何在python中没有for循环的情况下有条件地为给定组分配中值?
- amazon-web-services - AWS,如何更新 ssl 证书?
- r - 尝试使用 MikTeX 在 RStudio 中编译 PDF 无法生成引用,而是导致 [? ] 并且没有参考书目
- docker - docker 文件 arg 变量未传递给 Linux 上的 asp.net 核心
- google-chrome-devtools - 使用浏览器同步时无法在 Chrome 开发工具中编辑样式