This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Translate This Page

MathWorks Machine Translation

The automated translation of this page is provided by a general purpose third party translator tool.

MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.

Create Simple Model

You can use Simulink® to model a system and then simulate the dynamic behavior of that system.
Simulink allows you to create block diagrams, where blocks you connect represent
parts of a system, and signals represent input/output relationships between those
blocks. The primary function of Simulink is to simulate behavior of system components over time. In its simplest
form, this task involves keeping a clock, determining the order in which the blocks are
to be simulated, and propagating the outputs, computed in the block diagram, to the next
block. Consider a switch that turns on a heater. At each time step, Simulink must compute the output of the switch, propagate it to the heater, and
then compute the heat output.

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 (a state) 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:

Signals — Block inputs and outputs, computed during
simulation

States — Internal values, representing the dynamics of the block,
computed during simulation

Parameters — Values that affect the behavior of a block, controlled
by the user

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.

Model Overview

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.

A Simulink block is a model element that defines a mathematical relationship
between its input and output. To create this simple model, you need four Simulink blocks.

Block name

Block Purpose

Model Purpose

Pulse Generator

Generate an input signal for the model

Simulate the accelerator pedal

Gain

Multiply the input signal by a factor

Simulate how pressing the accelerator affects the car's
acceleration

Integrator, Second-Order

Integrate input signal twice

Obtain position from acceleration

Outport

Designate a signal as an output from the model

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

Use the Simulink Editor to build your models.

Start MATLAB®. From the MATLAB Toolstrip, click the Simulink button .

Click the Blank Model template.

The Simulink Editor opens.

From the File menu, select Save as. In the
File name text box, enter a name for your model,
For example, simple_model. Click
Save. The model is saved with the file extension
.slx.

Open Simulink Library Browser

Simulink provides a set of block libraries, organized by functionality in the
Library Browser. The following libraries are common to most workflows:

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

To browse through the block libraries, select a MathWorks® product and then a functional area in the left pane. To search all of
the available block libraries, enter a search term.

For example, find the Pulse Generator block. In the search box on
the browser toolbar, enter pulse, and then press the Enter key.
Simulink searches the libraries for blocks with pulse in
their name or description, and then displays the blocks.

Get detailed information about a block. Right-click a block, and then select
Help for the Pulse Generator block. The Help browser
opens with the reference page for the block.

Blocks typically have several parameters. You can access all parameters by
double-clicking the block.

Add Blocks to a Model

To start building the model, browse the library and add the blocks.

From the Sources library, drag the Pulse
Generator block to the Simulink Editor. A copy of the Pulse Generator block
appears in your model with a text box for the value of the
Amplitude parameter. Enter
1.

Parameter values are held throughout the simulation.

Add the following blocks to your model using the same approach.

Block

Library

Parameter

Gain

Simulink/Math
Operations

Gain: 2

Integrator, Second
Order

Simulink/Continuous

Initial condition:
0

Outport

Simulink/Sinks

Port number: 1

Add a second Outport block right-clicking and dragging the existing
one.

Your model should now have the blocks you need.

Arrange the blocks as follows by clicking and dragging each block. To
resize a block, click and drag a corner.

Connect Blocks

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

Click the output port on the right side of the Pulse
Generator block.

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

Click the input port of the Gain block.

Simulink connects the blocks with a line and an arrow indicating the
direction of signal flow.

Connect the output port of the Gain block to the input
port on the Integrator, Second Order block.

Connect the two outputs of the Integrator, Second Order
block to the two Outport blocks.

Save your model. Select File > Save and provide
a name.

Your model is complete.

Add Signal Viewer

To view the results, connect the first output to a Signal
Viewer.

Access the context menu by right-clicking the signal. Select Create
& 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.

Run Simulation

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

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

The default stop time of 10.0 is appropriate for
this model. This time value has no unit. Time unit in Simulink depends on how the equations are constructed. This example
simulates the simplified motion of a car for 10 seconds.