Documentation

创建简单的模型

You can use Simulink®建模系统,然后模拟该系统的动态行为。万博1manbetxSimulink允许您创建框图,其中您连接的块表示系统的部分,并且信号表示这些块之间的输入/输出关系。Simulink的主要功能是模拟随着时间的推移系万博1manbetx统组件的行为。以最简单的形式,此任务涉及保持时钟,确定要模拟块的顺序,并在框图中计算的输出传播到下一个块。考虑开关打开加热器的开关。在每个时间步骤中,Simulink必须万博1manbetx计算开关的输出,将其传播到加热器,然后计算热量输出。

Often, the effect of a component's input on its output is not instantaneous. For example, turning on a heater does not result in an instant change in temperature. Rather, this action provides input to a differential equation, and the history of the temperature (astate) is also a factor. When the simulation of a block diagram requires solving a differential or difference equation, Simulink employs memory and numerical solvers to compute the state values for the time step.

Simulink handles data in three categories:

  • 信号 - 在模拟期间计算的块输入和输出

  • 状态 - 内部值,代表模拟期间计算的块动力学

  • 参数 - 影响块行为的值,由用户控制

At each time step, Simulink computes new values for signals and states. By contrast, you specify parameters when you build the model and can occasionally change them while simulation is running.

模型概述

The basic techniques you use to create a simple model in this tutorial are the same techniques that you use for more complex models. This example simulates simplified motion of a car, after a brief press of the accelerator pedal.

Si万博1manbetxmulink块是一个模型元素,它定义了其输入和输出之间的数学关系。要创建这个简单的模型,您需要四个Simulink块。万博1manbetx

堵塞name 块目的 Model Purpose
Pulse Generator Generate an input signal for the model Simulate the accelerator pedal
获得 Multiply the input signal by a factor 模拟压迫器如何影响汽车的加速度
Integrator, Second-Order Integrate input signal twice Obtain position from acceleration
外港 将信号指定为模型的输出 Designate the position as an output from the model

Simulating this model integrates a brief pulse twice to get a ramp and then displays the result in a Scope window. The input pulse represents a press of the accelerator pedal in a car, and the output ramp represents the increasing distance from the starting point.

Open New Model

使用Simuli万博1manbetxnk编辑器来构建模型。

  1. 启动MATLAB®。From the MATLAB Toolstrip, click the万博1manbetxbutton

  2. 点击Blank Modeltemplate.

    The Simulink Editor opens.

  3. From the文件menu, select另存为。In the文件名text box, enter a name for your model, For example,simple_model。点击节省。The model is saved with the file extension。slx

Open万博1manbetx图书馆Browser

万博1manbetxSimulink提供了一组块库,该库由库浏览器中的功能组织。以下库对于大多数工作流程都是常见的:

  • Continuous — Building blocks for systems with continuous states

  • Discrete — Building blocks for systems with discrete states

  • 数学操作 - 实现代数和逻辑方程的块

  • 下沉 - 封锁存储并显示与它们连接的信号

  • 来源— Blocks that generate the signal values that drive the model

  1. 从Simulink万博1manbetx编辑器工具栏中,单击图书馆Browserbutton

  2. Set the Library Browser to stay on top of the other desktop windows. On the Library Browser toolbar, select the掌握button

To browse through the block libraries, select a MathWorks®产品,然后是左窗格中的功能区域。要搜索所有可用的块库,请输入搜索词。

例如,找到Pulse Generatorblock. In the search box on the browser toolbar, enter脉冲, and then press the Enter key. Simulink searches the libraries for blocks with脉冲in their name or description, and then displays the blocks.

Get detailed information about a block. Right-click a block, and then selectHelp for the Pulse Generator block。帮助浏览器在块的参考页面上打开。

块通常有几个参数。您可以双击块来访问所有参数。

Add Blocks to a Model

要开始构建模型,请浏览库并添加块。

  1. From the来源library, drag thePulse Generator块到Simulink编辑器万博1manbetx。副本Pulse Generatorblock appears in your model with a text box for the value of the振幅范围。进入1

    Parameter values are held throughout the simulation.

  2. 使用相同的方法将以下块添加到模型中。

    堵塞 图书馆 Parameter
    获得 万博1manbetx模型/Math Operations

    获得:2

    Integrator, Second Order 万博1manbetx模拟/连续

    Initial condition:0

    外港 万博1manbetx模型/Sinks

    端口号:1

    添加第二个外口块右键单击并拖动现有的块。

    Your model should now have the blocks you need.

  3. 通过单击和拖动每个块来排列以下块。要调整块大小,请单击并拖动角落。

Connect Blocks

Connect the blocks by creating lines between output ports and input ports.

  1. 点击output port on the right side of thePulse Generatorblock.

    The output port, and all input ports suitable for a connection get highlighted.

  2. 单击输入端口获得block.

    万博1manbetxSimulink用一条线和箭头连接块,指示信号流的方向。

  3. 连接输出端口获得块到输入端口Integrator, Second Orderblock.

  4. Connect the two outputs of theIntegrator, Second Orderblock to the two外港块。

  5. 保存您的模型。选择文件> Saveand provide a name.

您的模型已完成。

Add Signal Viewer

要查看结果,请将第一个输出连接到Signal Viewer

Access the context menu by right-clicking the signal. SelectCreate & Connect Viewer > Simulink > Scope。This creates a viewer icon on the signal, and opens a Viewer display.

You can open the viewer at any time by double-clicking the icon.

运行模拟

After you define the configuration parameters, you are ready to simulate your model.

  1. On the model window, set the simulation stop time by changing the value at the toolbar.

    The default stop time of10.0适合此模型。此时间值没有单位。Simulink中的时间单万博1manbetx元取决于方程的构造方式。此示例模拟了汽车的简化运动10秒。

  2. 要运行模拟,请单击Run仿真按钮

The simulation runs and produces the output on the Viewer.

See Also

相关话题

这个话题有帮助吗?