Tutorial Program Simulink Matlab 2022
Tutorial Program Simulink Matlab 2022
2
Launch Simulink
In the MATLAB command window,
at the >> prompt, type simulink
….. Or click this
and press Enter
3
Create a new model
4
Your workspace
Library of elements Model is created in this window
5
Save your model
• You might create a new folder, like the one shown below,
called simulink_files
• Use the .mdl suffix when saving
6
Example 1: a simple model
• Build a Simulink model that solves the
differential equation
x 3 sin 2t
• Initial condition
x(0) 1.
x 1 x
3sin(2t) x(t)
s
(input) (output)
integrator
9
Select an operator block
Drag an Integrator block
from the Continuous library
to the model window
10
Select an output block
Drag a Scope block from the
Sinks library to the model
window
11
Connect blocks with signals
• Place your cursor on the
output port (>) of the Sine
Wave block
• Drag from the Sine Wave
output to the Integrator input
• Drag from the Integrator
output to the Scope input
12
Select simulation parameters
Double-click on
the Sine Wave
block to set
amplitude = 3
and freq = 2.
13
Select simulation parameters
Double-click on
the Integrator
block to set
initial condition
= -1.
14
Select simulation parameters
Double-click on
the Scope to view
the simulation
results
15
Run the simulation
In the model
window, from the
Simulation pull-
down menu,
select Start
16
Simulation results
To verify that this
plot represents the
solution to the
problem, solve the
equation analytically.
17
Example 2
• Build a Simulink model that solves the
following differential equation
– 2nd-order mass-spring-damper system
– zero ICs
– input f(t) is a step with magnitude 3
– parameters: m = 0.25, c = 0.5, k = 1
mx cx kx f (t )
18
Create the simulation diagram
• On the following slides:
– The simulation diagram for solving the ODE is
created step by step.
– After each step, elements are added to the
Simulink model.
• Optional exercise: first, sketch the complete
diagram
mx cx kx f (t )
19
(continue)
• First, solve for the term with highest-order
derivative
mx f (t ) cx kx
mx
summing
block 20
Drag a Sum block from
the Math library
21
(continue) mx cx kx f (t )
mx 1 x
m
summing
block
22
Drag a Gain block from
the Math library
Double-click to change
the block parameters.
Add a title.
23
(continue) mx cx kx f (t )
mx 1 x 1 x 1 x
m s s
summing
block
24
Drag Integrator blocks from
the Continuous library
mx 1 x 1 x 1 x
m s s
summing cx
block c
kx k
26
Drag new Gain blocks
from the Math library
To flip the gain block, select it
and choose Flip Block in the
Format pull-down menu.
c=0.5
Double-click on gain
blocks to set parameters
Connect from the gain
block input backwards up
to the branch point. k=1.0
Re-title the gain blocks.
27
Complete the model
mx cx kx f (t )
• Bring all the signals and inputs to the
summing block.
• Check signs on the summer.
28
Double-click on Step block
to set parameters. For a
step input of magnitude 3,
set Final value to 3
29
Final Simulink model
30
Run the simulation
31
Results
Underdamped response.
Overshoot of 0.5.
Final value of 3.
Is this expected?
32
Paper-and-pencil analysis
based on the equations of motion
• Standard form x c 1
x x f (t )
k k k
m
• Nat’l freq. n
k
2.0
m
2 c
• Damping ratio 0.5
n k
• Static gain K
1
1
k
33
Check simulation results
• Damping ratio of 0.5 is less than 1.
– Expect the system to be underdamped.
– Expect to see overshoot.
• Static gain is 1.
– Expect output magnitude to equal
input magnitude.
– Input has magnitude 3, so does output.
mx cx kx f (t )
x c 1
x x f (t ) m = 0.25, c = 0.5, k = 1, f(t) = 3
k k k
m
k 2 c 1
n 2.0 0.5 K 1
m n k k 34
End of tutorial