主要内容

万博1manbetxSimulink模拟

模拟动态系统的模型使您可以深入了解所提出的系统设计的行为,而无需实际构建系统的耗时过程。本主题中的概念为理解如何使用Simulink控制模型模拟提供了一个背景万博1manbetx®software tools.

编译

汇编是模拟过程万博1manbetxblock diagramis translated to an internal representation that interacts with the Simulink engine.

There are no model-level sets of differential equations that are solved numerically as a whole. Instead, the model-level equations correspond to the individual block equations that are solved numerically in a specific order.

块方法

functionality of a single block is defined by multiple equations. These equations are represented as block methods. These block methods are evaluated (executed) during the execution of a block diagram. The evaluation of these block methods is performed within a simulation loop, where each cycle through the simulation loop represent the evaluation of the block diagram at a given point in time. Common block methods include:

  • 导数 - 在当前时间步骤中计算块连续状态的衍生物,给定块输入和上一个时间步骤的状态值。

  • Update – Computes the value of the block's discrete states at the current time step, given its inputs at the current time step and its discrete states at the previous time step.

  • 输出 - 在当前时间步长及其状态下,计算块的输出,在上一个时间步骤中。

Equations that describe the model states, the derivative method, the update method, the output method, and the initial model states

模型方法

除了块方法外,还提供了一组计算模型属性及其输出的方法。Simu万博1manbetxlink软件在模拟过程中类似地调用这些方法,以确定模型的属性及其输出。模型方法通常通过调用相同类型的块方法执行其任务。例如,模型输出方法调用了它在计算其输出的模型指定的顺序中包含的块的输出方法。模型衍生物方法类似地调用了它包含的块的衍生物方法来确定其状态的衍生物。

See also:动态系统中的仿真阶段

打回来

打回来s are MATLAB expressions that execute in response to a specific modeling action. Simulink provides model, block, and port callback parameters that identify specific kinds of modeling actions. You provide the code for callback parameters. Simulink executes the callback code when the associated modeling action occurs.

模型回调

模型回调参数包括:

  • 预载体- 在型号加载之前执行。例如,您可以提供将模型使用的变量值加载到MATLAB工作区中的代码。

See模型回调

块回调

Block callback parameters include:

  • OpenFCN- 打开时执行子系统block.

  • LOADFCN– Execute after a diagram is loaded. For a子系统块,还执行块中的块回调参数子系统block.

端口回调

端口回调参数:

  • ConnectionCallback- Execute code every time the connectivity of a port changes.

See端口回调s

Execution Order

执行顺序是在评估每个输入端口的直接进料后调用块输出方法的序列。要显示执行顺序,在调试选项卡,选择Information Overlays>Execution Order

在以下模型中,集成商块输出首先运行,然后连接到集成商block input. Missing execution numbers in a sequence are usually due to so-called "hidden buffer" blocks; see确保外口是虚拟的

Model with a feedback loop that consists of a Gain block, an Integrator block, a second Gain block, and a Sum block

See also:控制和显示执行顺序,动态系统中的仿真阶段

模拟

模拟是模型之后的过程汇编where block method outputs and states are computed at successive time steps over a specified time range using a numerical solver.

在每个模拟循环期间,Simulink计算A万博1manbetxΔTto determine the time stept(k+1) = t(k) + Δt。的大小ΔTis based on an estimated error between the simulated solution and the actual solution. At the end of a simulation, data results are given as vectors[t, X, Y]在每个时间步骤中,状态和输出。

该图将仿真过程显示为三个块:首先,初始化,其中t = t = tstart,第二,计算时间步,执行模型步骤并重复直至终止的仿真循环,第三,终止,其中t =tfinal。

See also:动态系统中的仿真阶段,交互模拟模型,加快模拟

求解器

A Solver finds an approximate solution for a set of model equations. Simulink uses established numerical solvers for this task.

求解器step size can be fixed or variable:

  • Fixed step – Time stept(k + 1)= t(k) +ΔtwhereΔTis constant. If step size is too large, simulation results can have a large error. In the following example, a step size of2扭曲正弦波信号的形状。您可以在固定步骤求解器的情况下指定时间步长的大小,或者求解器可以自动确定可变步骤求解器的步骤大小。

    Two plots of the sine wave, one with a large step size (left), and one with a small step size (right)

  • 可变步骤 - 可变步骤求解器迭代以基于误差耐度达到解决方案。时间步骤t(k + 1)= t(k) +ΔtₖwhereΔTₖchanges from one simulation step to the next depending on the estimated error. Smaller time steps increase the accuracy of the simulation results. To minimize the computation workload, a variable-step solver chooses the largest step size consistent with achieving an overall level of precision specified by the error tolerance and observing zero-crossings. This ensures that all model states are computed to the accuracy specified by the user.

选择求解器方法取决于模型方程的性质。Euler的方法是一个简单的数值求解器,可以计算yby using the slope (是的) of a tangent line toy。Ify是将斜坡函数x与斜率为1集成的函数y'= x,并且数值求解器将使用以下方程式。

x [n+1] = x [n]+Δt*1 y [n+1] = y [n]+Δt*x [n+1]

减小步长会提高结果的准确性。但这增加了完成模拟的时间。在下面的示例中,一个步骤的大小2shows an error of about 20 percent after 10 seconds while a step size of0.5produces a result that is closer to the actual solution.