0% found this document useful (0 votes)
39 views44 pages

Part 2-1: Numerical Simulation of Dynamic Systems

This document discusses numerical simulation of dynamic systems using MATLAB and Simulink, focusing on modeling, simulating linear time-invariant (LTI) systems, and standard input functions. It outlines the goals of simulating system responses to various inputs and provides detailed steps for using MATLAB commands and Simulink for simulations. The document also covers the advantages of numerical simulations, including ease of use and the ability to handle complex system dynamics.

Uploaded by

mohammad.askar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views44 pages

Part 2-1: Numerical Simulation of Dynamic Systems

This document discusses numerical simulation of dynamic systems using MATLAB and Simulink, focusing on modeling, simulating linear time-invariant (LTI) systems, and standard input functions. It outlines the goals of simulating system responses to various inputs and provides detailed steps for using MATLAB commands and Simulink for simulations. The document also covers the advantages of numerical simulations, including ease of use and the ability to handle complex system dynamics.

Uploaded by

mohammad.askar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Part 2-1: Numerical Simulation of

Dynamic Systems
• So far, we have covered the following topics:
– Modeling dynamic systems
– Standard forms to represent dynamic systems

• Next, we will introduce the use of numerical methods


(MATLAB and Simulink) to obtain the dynamic system’s
response, using system models in standard forms

• Goals of this chapter:


– Simulate LTI systems using built-in MATLAB commands
– We will investigate system response to standart inputs (such as
the step, ramp, sinusoid) or arbitrary inputs.
– Construct and execute a simulation of a dynamic system using
MATLAB’s graphical software Simulink
Desirable Traits of Numerical Simulations

• Ease of entering the system dynamics


– Transfer functions
– Integrator blocks
– State-space representation (SSR)

• Ability to include initial conditions

• Ability to include arbitrary input functions

• Ease of storing and plotting the output (response) variables

• Ease of changing the run-time and integration parameters


– Start/stop time
– Integration step size
– Integration method (Euler’s method, Runge-Kutta, etc)
Standard Input Functions in
Simulations

• System performance is often characterized by the system’s


dynamic response to any number of standard input functions

• We can think of these “standard” input functions as “test


input signals” for characterizing the system’s dynamic response

• Many standard input functions have a basis in the realistic


(expected) input for a dynamic system
Step Input
• The step input shows a sudden, instantaneous change (step)
from one constant value to another constant value
U(t)
Unit-step input
1
ì0 for t £ 0
U (t ) = í
î1 for t > 0 t
0

• Many times the step input is initially zero and instantaneously


steps to a constant value

• Step input with magnitude of A : u (t ) = AU (t )


Ramp Input
• A ramp input function increases linearly with time at a
constant rate
u(t)

Unit-ramp input u (t ) = t Slope = 1

t
0

• A general ramp input is u (t ) = at where a is the slope, which


could be positive or negative
Ramped Step Input
• The input “ramps” up from zero to a constant (step) value

• The ramp-up component shows a linear increase with time

• The ramped step input might be a more realistic


representation of a step input, since most physical inputs
require a finite time interval to change from one constant
value to another constant value

Ramped step input u(t)

A
ìat for 0 £ t £ A / a
u (t ) = í
î A for t > A/ a
t
0
Pulse Input
• The input has a constant (finite) magnitude over a finite time
interval (the “pulse duration”), and is zero before and after
the pulse is applied

Pulse input
u(t)
ì 0 for t£0 A
ï
u (t ) = í A for 0 < t < t1
ï 0 for t ³ t1
î
t
0 t1
Impulse Input
• The input has a magnitude that lasts for a very short duration

• We can think of the impulse input as a pulse function where


the pulse duration goes to zero in the limit, i.e., Dt à 0

• Suppose a constant force F = 150 N is applied for a very short


duration Dt = 0.1 sec (a pulse input)
– Therefore, the impulse input has a “strength” of 15 N-s,
which is the area of the original pulse function
– Note that the units of an impulse input contain units of
time; for a force input, an impulse has units of N-s.
Impulse Input (2)

• Pulse force inputs with an impulse of 15 N-s


Impulse Input (3)
• Mathematically, and unit impulse input is represented by the
Dirac delta function, d(t), which has infinite magnitude but
infinitesimally small time duration, and hence the “area” of
the pulse is unity

• Suppose we have a short-duration force input with “weight”


or “strength” of 15 N-s (such as shown in prior slide)

f (t ) = 15d (t ) N f(t), N

• The “weight” of the impulse 15


is 15 N-s and hence d(t) has
units of 1/sec
t
0
Sinusoidal Input
• A sinusoidal input function is a repeating, periodic input that
can be represented by sine and/or cosine functions
Harmonic input fuction (frequency is 0.5 Hz)
3

Sinusoidal input 2

u (t ) = A sin wt + B cos wt 1

Input
0

A and B are amplitudes -1

and w is the (angular) frequency


in rad/s (w = 2p f )
-2

-3
0 1 2 3 4 5
Frequency is sometimes expressed Time, sec

in cycles/sec or hertz (Hz)

Example: w = 3.14 rad/s, if frequency is 0.5 Hz


System Response Using
MATLAB Commands
• It is fairly easy to obtain the response of a linear time-invariant (LTI)
system with MATLAB

• Example: consider the simple second-order linear model (I/O Eq.)


!y! + 3 y! + 12 y = 0.8u y = output, u = input
0.8 Y (s)
• The transfer function is G ( s ) = 2 =
s + 3s + 12 U ( s )

• We have several options for computing the unit-step response

Option #1: use the “step.m” M-file


>> numG = 0.8; % define numerator of G(s)
>> denG = [1 3 12]; % define denominator polynomial in s
>> sys = tf(numG,denG) % build TF system using numG and denG
>> step(sys) % compute and plot unit-step response to the screen
System Response Using
MATLAB Commands (2)
Option #2: use “lsim.m” M-file (general linear simulation M-file)
>> numG = 0.8; % define numerator of G(s)
>> denG = [1 3 12]; % define denominator polynomial in s
>> sys = tf(numG,denG); % build TF system using numG and denG
>> t = 0 : 0.01 : 5; % define simulation time span (0 to 5 sec by increments of 0.01)
>> u = ones(size(t)); % define the unit-step input (all 1’s; same size vector as time t)
>> lsim(sys,u,t); % compute linear simulation with arbitrary input; plots result

Options for plotting:


Use left-hand side arguments for storage:

>> [y,t] = lsim(sys,u,t);

Then, the user must plot results:

>> plot(t,y)
>> grid
>> xlabel(‘Time, sec’)
>> ylabel(‘Output, y’)
System Response Using
MATLAB Commands (3)
• Suppose that the input is a unit impulse at t = 0. Again, we have
several options for simulating the system response with MATLAB

Option #1: use the “impulse.m” M-file


>> numG = 0.8; % define numerator of G(s)
>> denG = [1 3 12]; % define denominator polynomial in s
>> sys = tf(numG,denG); % define system as TF
>> impulse(sys) % compute unit-impulse response and plots

Option #2: use “lsim.m” M-file


>> numG = 0.8; % define numerator of G(s)
>> denG = [1 3 12]; % define denominator polynomial in s
>> sys = tf(numG,denG)
>> dt = 0.01; % define time increment (delta-t)
>> t = 0 : dt : 5; % define simulation time span (0 to 5 sec by increments of 0.01)
>> u = zeros(size(t)); % define the input as all 0’s with same size vector as time t
>> u(1) = 1/dt; % define the impulse input so that strength (“area”) is 1
>> lsim(sys,u,t); % compute linear simulation with arbitrary input; plots result
System Response Using
MATLAB Commands: SSR
• If we have a SISO system described in state-space, the unit-
step response is easy to obtain by using the MATLAB
commands:

>> A = [ 0 1 ; -12 -3 ]; % A matrix (2x2)


>> B = [ 0 ; 0.8 ]; % B matrix (2x1)
>> C = [ 1 0 ]; % C matrix (1x2)
>> D = [ 0 ]; % D matrix
>> sys = ss(A,B,C,D) % define SSR system

Now, we can compute the unit-step or unit-impulse response:

>> step(sys) -or- >> impulse(sys)


Notes on step.m and impulse.m

• M-files step.m and impulse.m assume that the system has zero
initial conditions
– Of course, a system represented by a transfer function has zero
initial conditions by definition

• For systems with non-zero initial conditions we must use a


state-space representation (SSR)

• Two options: lsim.m and initial.m

>> [y,t] = lsim(sys,u,t,x0); % sys is SSR, x0 is the initial state

>> [y,t] = initial(sys,x0,t); % sys is SSR, x0 is initial state (no input)


Building Simulations
Using Simulink

• The MATLAB/Simulink software is an extremely useful


tool for simulating the dynamic response of a system.

• Simulink is a graphical computer package based on


block diagrams and transfer functions (TFs)

• Reasons for computer-based simulation methods:


– We must use numerical (computer) methods to obtain the
dynamic response if the model is nonlinear
– Numerical simulation may be necessary if the order of the model
is > 3 (analytical methods are too tedious!)
– Numerical simulations can handle arbitrary input functions
Simulink Primer
• To start Simulink, start the MATLAB program and enter “simulink”
on command line:

>> simulink

• Clicking on the “new model” icon in the upper left corner will create
a new Simulink model, which begins as a blank template for
building the simulation block diagram

• Construct the block diagram model by selecting blocks from the


appropriate library and copying them to the open template by
clicking and dragging-and-dropping

• Libraries:
– Sources (input signals like step, ramp, sine; clock time, etc)
– Sinks (plots and save output data: “scope”, “to workspace”)
– Continuous (TFs, state-space models, integrators, etc)
– Math Operations (gains, trig functions, summing junctions, etc)
– Discontinuous (nonlinear effects like Coulomb friction, backlash,
saturation, etc)
– Signal Routing (mux, demux, switches, etc)
Simulating Linear Systems
Using Simulink
• System model: m!y! + by! + ky = f (t ) y = position from equilibrium
f(t) = EM force (input)
System is initially at rest

3-way spool valve

• The transfer function is


Y ( s) 1 Let m = 0.04 kg, b = 16 N-s/m, and
= G( s) = 2
F ( s) ms + bs + k k = 7000 N/m
3-way Spool Valve:
Example (2)
The EM force is a 12-N step input that steps up at t = 0.02 sec

Simulink steps:

1. Set the constant 12-N input force by using the “step” block from the “Sources”
library. Set the “step time” to 0.02 and set the “final value” (magnitude) to 12

2. Click/drag the TF icon from the “Continuous” library. Set the system parameters
(m, b, k) by entering the TF numerator and denominator polynomials as row
vectors in descending powers of “s”. Once the values are applied, the block
will show the TF with powers of s.

3. Double-click on the blocks to label variables and label block titles.


3-way Spool Valve:
Example (3)
Simulink steps: (continued)

4. Click/drag “To Workspace” icon from “Sinks” library. Double-click on the


“to workspace” blocks, and set variable names and set “save format” to “array.”

5. Set the run-time parameters by choosing “Configuration Parameters” from the


Simulation menu. Set the stop time to 0.1 sec and change the max step size
from “auto” to 1E-4 sec to “smooth” the jagged time response due to too
few data points (i.e., large time step).

6. Click on the “start” or “play” button to execute the simulation.

7. Plot the dynamic response by returning to the MATLAB environment. Use


the “plot” command:
>> plot(t,y) ( plots stored values of x vs t)
>> grid (draws grid lines)
>> title(‘Step response of 3-way valve’) (add title to plot)
>> xlabel(‘Time, sec’) (x-axis label)
>> ylabel(‘Position, y, m’) (y-axis label)
3-way Spool Valve:
Example (4)

Simulink model for 3-way valve mechanical system


using a transfer function for the system dynamics
3-way Spool Valve:
Step Response
3-way Spool Valve Using SSR:
Example
State Equation Output Equation
é x!1 ù é 0 1 ù é x1 ù é 0 ù é x1 ù
x! = ê ú = ê ú ê ú + ê úu y = [1 0]ê ú + [0]u
ë x! 2 û ë - 175,000 - 400û ë x 2 û ë25û ë x2 û
A C D
B
Simulink steps:
1. Set the constant 12-N input force by using the “step” block from
the “Sources” library. Set the “step time” to 0.02 and set the
“final value” (magnitude) to 12

2. Click/drag the State-Space icon from the “Continuous” library.


Set the system matrices (A, B, C, D) by double-clicking on the
State-Space icon and using the dialog boxes

3. Remaining steps are the same as Example 6.4…


3-way Spool Valve Using SSR:
Example (2)

Simulink model for 3-way valve mechanical system


using a State-Space block

Simulation results are the same as the previous example


Simulation with Integrator-Block Method
Example
• Note that with the transfer function approach, we cannot
include initial conditions (ICs) in the simulation due to the
definition of a TF (e.g., zero IC)

• Also, suppose that we wanted to compute and store velocity


of the mass
– The output of the TF is position y and not velocity

• Solution: use “integrator blocks” (Continuous library) to


integrate each derivative term

• The integrator-block method can also be used to simulate


nonlinear systems (more flexible than TF…)
Integrator-Block Method:
Example (2)
• Recall the mechanical system’s dynamics: m!y! + by! + ky = f (t )

• Because the model is 2nd order, we need two integrators

• The first integrator will integrate !y! to produce y! ; the second


integrator will integrate velocity y! to produce position y

• We can set initial conditions for velocity and position by


double-clicking the respective integrator blocks
Integrator-Block Method:
Example (3)
• Simulink block diagram using integrator blocks

Two successive integrations

Simulation results are the same as previous examples with TF and SSR
Simulating Linear Systems: Summary
• The transfer-function approach is likely the most concise and
easiest method to use. However, by definition, a transfer
function cannot be used when the system has non-zero initial
conditions

• The state-space approach is concise but it requires the user


derive the complete state-space representation matrices.
However, it is flexible since it allows the user to set arbitrary
initial conditions for all n states

• The integrator-block approach is likely the most flexible method,


since it allows the user to set arbitrary initial conditions for all
dynamic variables; plus, the user can store and plot any signal-
path variable, which may aid in trouble-shooting complex
simulations
Simulating Nonlinear Systems:
Example
• Consider the case where friction is modeled by Coulomb
(dry) friction plus viscous friction
– Therefore, a certain amount of force must be present to overcome
“dry” friction force Fdry, and the total friction on the mass is the
Coulomb (dry) friction plus viscous friction:

m!y! + by! + Fdry sgn( y! ) + ky = f (t )


– Dry friction is a nonlinear effect, and it can be modeled using the
signum (sign) function

• The mass-spring-damper model is repeated (next slide)


with the Coulomb + viscous friction (Fdry = 0.4 N)

0.04 !y! + 16 y! + 0.4 sgn( y! ) + 7000 y = f (t ) 3-way spool valve


with dry friction
Nonlinear System: 3-Way Valve
Example (2)

Dry friction
3-Way Valve Step Response
Nonlinear and Linear Models
Example

Input is f(t) = 12-N step function


Building Integrated Systems

“Clean” method for constructing complex simulations

Basic idea: 1) Create each subsystem separately using Simulink


2) Build “subsystem” by enclosing with “bounding box”
(see Appendix C)
3) OR, use Subsystem block from Ports & Subsystems library
Solenoid Actuator-Valve System
Example

Two “subsystems” 1) Electrical RL coil


2) Mechanical mass-spring-damper
Solenoid Actuator-Valve:
Example (2)

LI! + RI = ein (t ) - KIx! Solenoid coil (electrical)

m!x! + bx! + Fdry sgn( x! ) + kx = Fem Mechanical valve

EM force: Fem = 0.5 KI 2


Electrical Subsystem

Solenoid coil dynamics

LI! + RI = ein (t ) - KIx!


EM force:

Fem = 0.5 KI 2
Electrical Subsystem (2)
(after enclosing with “bounding box” and creating subsystem)

RL coil dynamics

LI! + RI = ein (t ) - KIx!


EM force:

Fem = 0.5 KI 2
Mechanical Subsystem

m!x! + bx! + Fdry sgn( x! ) + kx = Fem Mechanical valve dynamics


Mechanical Subsystem (2)
(after enclosing with “bounding box” and creating subsystem)

m!x! + bx! + Fdry sgn( x! ) + kx = Fem Mechanical valve dynamics


Integrated Solenoid System:
Example
System Parameters:
Solenoid Actuator-Valve

System parameter Value


Coil resistance, R 3W
Coil inductance, L 0.005 H
Force/back-emf constant, K 6 N/A2
Armature-valve mass, m 0.03 kg
Viscous friction coefficient, b 12 N-s/m
Spring constant, k 6000 N/m
Dry friction force, Fdry 0.5 N
M-file for Simulation
%
% run_EMA.m
%
% This M-file sets the modeling parameters for the
% electromagnetic actuator (EMA), executes the
% Simulink model, and plots the dynamic variables
%

% Solenoid electrical circuit parameters


e_in = 10; % step input voltage
R = 3; % coil resistance, Ohms
L = 0.005; % coil inductance, H
K = 6; % dL/dx (back-emf and force constant), N/A^2

% Mechanical parameters
m = 0.03; % armature-valve mass, kg
b = 12; % viscous friction coefficient, N-s/m
k = 6000; % return spring constant, N/m
F_dry = 0.5; % dry friction force, N

% run Simulink model


sim integrated_EMA

% plots
figure(1)
plot(t,1e3*x)
grid
xlabel('Time, s')
ylabel('Armature-valve position, x(t), mm')

figure(2)
plot(t,I)
grid
xlabel('Time, t, sec')
ylabel('Solenoid current, I(t), A')
Valve Position vs. Time
10-V Step Input

Steady-state
position

xss = Fem / k
Solenoid Current vs. Time
10-V Step Input

Steady-state
current

Iss = 10 V / 3 W

You might also like