您可以使用块Modelica.Blocks.Continuous.StateSpace 来构建包含状态空间描述的模型,如下所示:
各自的代码是:
model StateSpaceModel
Modelica.Blocks.Continuous.StateSpace sys annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Modelica.Blocks.Sources.Step step(startTime=0.5) annotation (Placement(transformation(extent={{-60,-10},{-40,10}})));
equation
connect(step.y, sys.u[1]) annotation (Line(points={{-39,0},{-12,0}}, color={0,0,127}));
annotation (uses(Modelica(version="4.0.0")));
end StateSpaceModel;
此外,您还可以使用一个脚本(或 Modelica 函数)来为您工作。更准确地说,它
- 线性化任何合适的模型。我使用了 MSL 本身的状态空间模型,因此您可以确定结果是正确的。
- 将上述模型翻译成能够从命令行设置参数
- 设置名为
sys 的状态空间块的参数。这包括x_start 中的初始条件
- 使用新参数模拟模型
// Get state-space description of a model
ss = Modelica_LinearSystems2.ModelAnalysis.Linearize("Modelica.Blocks.Continuous.StateSpace");
// Translate custom example, set parameters to result of the above linearization, add initial conditions for states and simulate
translateModel("StateSpaceModel")
sys.A = ss.A;
sys.B = ss.B;
sys.C = ss.C; // in case of an error here, check if 'OutputCPUtime == false;'
sys.D = ss.D;
sys.x_start = ones(size(sys.A,1));
simulateModel("StateSpaceModel", resultFile="StateSpaceModel");