Tải bản đầy đủ (.pdf) (28 trang)

Ch 05 state variabe modes and simulation methods

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.21 MB, 28 trang )

11/17/2012

System Dynamics

5.01

State Variable Models and Simulation Methods

5. State Variable Models and
Simulation Methods

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.01

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models
- Consider the second-order equation
5𝑦 + 7𝑦 + 4𝑦 = 𝑓(𝑡)
- Define
𝑥1 ≡ 𝑦
𝑥1 = 𝑦
𝑥2 ≡ 𝑦 ⟹ 𝑥2 = 𝑦
then
𝑥1 = 𝑥2
4


7
𝑥2 = − 𝑥1 − 𝑥2 + 𝑓(𝑡)
5
5
- These two equations, called the state equations, are the statevariable form of the model, and the variables 𝑥1 and 𝑥2 are
called the state variables
- The choice of state variables is not unique, but the choice
must result in a set of first order differential equations
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

1


11/17/2012

System Dynamics

5.03

State Variable Models and Simulation Methods

§1. State Variable Models
- Example 5.1.1
State-Variable Model of a Two-Mass System
Consider the two-mass system with the
equations of motion
5𝑥1 + 12𝑥1 + 5𝑥1 − 8𝑥2 − 4𝑥2 = 0
3𝑥2 + 8𝑥2 + 4𝑥2 − 8𝑥1 − 4𝑥1 = 𝑓(𝑡)

Put these equations into state-variable form
Solution
Define 𝑧1 ≡ 𝑥1 , 𝑧2 ≡ 𝑥1 , 𝑧3 ≡ 𝑥2 , 𝑧4 ≡ 𝑥2
Then 𝑧1 = 𝑧2
12
4
8
𝑧2 = −𝑧1 − 𝑧2 + 𝑧3 + 𝑧4
5
5
5
𝑧3 = 𝑧4
4
8
4
8
1
𝑧4 = 𝑧1 + 𝑧2 − 𝑧3 − 𝑧4 + 𝑓(𝑡)
3
3
3
3
3
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.04

Nguyen Tan Tien


State Variable Models and Simulation Methods

§1. State Variable Models
1.Vector-Matrix Model of State-Variable Models
- Vector-matrix notation enables us to represent multiple
equations as a single matrix equation
- Example
2𝑥1 + 9𝑥2 = 5
3𝑥1 − 4𝑥2 = 7
can be represented in the form
2 9 𝑥1
5
=
𝑥
3 −4 2
7
or
𝑨𝒙 = 𝒃
𝑥1
2
9
5
𝑨=
,𝒙= 𝑥 ,𝒃=
3 −4
2
7

HCM City Univ. of Technology, Faculty of Mechanical Engineering


Nguyen Tan Tien

2


11/17/2012

System Dynamics

5.05

State Variable Models and Simulation Methods

§1. State Variable Models
- Example 5.1.2
Vector-Matrix Form of a Single-Mass Model
Express the mass-spring-damper model
𝑥1 = 𝑥2
1
𝑘
𝑐
𝑥2 = 𝑓 𝑡 − 𝑥1 − 𝑥2
𝑚
𝑚
𝑚
as a single vector-matrix equation
Solution
The equations can be written as one equation as follows
0

1
0
𝑥1
𝑥1
1 𝑓(𝑡)
𝑘
𝑐
=
+
𝑥2
𝑥2


𝑚
𝑚
𝑚
In compact form this is
𝒙 = 𝑨𝒙 + 𝒃𝑓(𝑡)
0
1
0
𝑥1
𝑘
𝑐 ,𝒃 = 1
𝒙 = 𝑥 ,𝑨 =


2
𝑚
𝑚

𝑚
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.06

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models
- Example 5.1.3
Vector-Matrix Form of the Two-Mass Model
Express the model
𝑧1 = 𝑧2 ,

𝑧2 = −𝑧1 −

𝑧3 = 𝑧4 ,

𝑧4 = 3 𝑧1 +

4

12
4
8
𝑧2 + 𝑧3 + 𝑧4
5

5
5
8
4
8
1
𝑧 − 3 𝑧3 − 3 𝑧4 + 3 𝑓(𝑡)
3 2

in vector-matrix form
Solution
In vector-matrix form these equations are
𝒛 = 𝑨𝒛 + 𝒃𝑓
0
1
0
0
0
𝑧1
12
4
8
−1 − 5
0
𝑧2
5
5
𝒛= 𝑧 ,𝑨=
,𝒃= 0
0

0
0
1
3
1
4
8
4
8
𝑧4


3
3
3
3
3
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

3


11/17/2012

System Dynamics

5.07


State Variable Models and Simulation Methods

§1. State Variable Models
2.Standard Form of the State Equation
𝒙 = 𝑨𝒙 + 𝑩𝒖
𝒙: 𝑛 × 1 state vector
𝑨: 𝑛 × 𝑛 system matrix
𝑩: 𝑛 × 𝑚 control or input matrix
𝒖: 𝑚 × 1 input vector
3.The Output Equation
- The output vector contains the variables that are of interest
for the particular problem at hand
𝒚 = 𝑪𝒙 + 𝑫𝒖
𝒚: 𝑝 × 1 output vector
𝑪: 𝑝 × 𝑛 state output matrix
𝑫: 𝑝 × 𝑚 control output matrix
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.08

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models
- Example 5.1.4 The Output Equation for a Two-Mass Model
Consider the two-mass model
5𝑥1 + 12𝑥1 + 5𝑥1 − 8𝑥2 − 4𝑥2 = 0

3𝑥2 + 8𝑥2 + 4𝑥2 − 8𝑥1 − 4𝑥1 = 𝑓(𝑡)
a. Suppose the outputs are 𝑥1 and 𝑥2 . Determine the output
matrices 𝑪 and 𝑫
b. Suppose the outputs are 𝑥2 − 𝑥1 , 𝑥2 , and 𝑓. Determine the
output matrices 𝑪 and 𝑫
Solution
0
1
0
0
0
𝑧1
12
4
8
−1

0
𝑧2
5
5
5
𝒛 = 𝑨𝒛 + 𝒃𝑓, 𝒛 = 𝑧 , 𝑨 =
,𝒃= 0
0
0
0
1
3
1

4
8
4
8
𝑧4


3
3
3
3
3
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

4


11/17/2012

System Dynamics

5.09

State Variable Models and Simulation Methods

§1. State Variable Models
a.The outputs are 𝑥1 and 𝑥2
𝑥1

𝑧1
1
𝒚= 𝑥 = 𝑧 =
3
0
2
⟹ 𝒚 = 𝑪𝒙 + 𝑫𝑓
where
1 0 0
𝑪=
0 0 1
0
𝑫=
0

𝑧1
0 0 0 𝑧2
0
+
𝑓
0 1 0 𝑧3
0
𝑧4

0
0

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics


5.10

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models
b.The outputs are 𝑥2 − 𝑥1 , 𝑥2 , and 𝑓

𝑧1
−𝑥1 + 𝑥2
−𝑧1 + 𝑧3
−1 0 1 0 𝑧
0
2
𝑧4
𝑥2
𝒚=
=
= 0 0 0 1 𝑧 + 0 𝑓
3
𝑓
𝑓
0 0 0 0 𝑧
1
4
⟹ 𝒚 = 𝑪𝒙 + 𝑫𝑓
where
−1 0 1 0

𝑪= 0 0 0 1
0 0 0 0
0
𝑫= 0
1

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

5


11/17/2012

System Dynamics

5.11

State Variable Models and Simulation Methods

§1. State Variable Models
3.Model Forms having Numerator Dynamics
Consider the model with numerator dynamics or input derivatives
𝑑3𝑦
𝑑2 𝑦
𝑑𝑦
𝑑𝑓
5 3 +3 2 +7
+ 6𝑦 = 4

+ 9𝑓(𝑡)
𝑑𝑡
𝑑𝑡
𝑑𝑡
𝑑𝑡
With the existence of
𝑑𝑓
𝑑𝑡
the state variables are not so easy to identify to put the model
in the standard form
𝒙 = 𝑨𝒙 + 𝒃𝑢
𝒚 = 𝑪𝒙 + 𝑫𝑢

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.12

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models
- Example 5.1.5 Numerator Dynamics in a First-Order System
Consider the transfer function and its corresponding equation
𝑍(𝑠) 5𝑠 + 3
=
,
𝑧 + 2𝑧 = 5𝑢 + 3𝑢

𝑈(𝑠)
𝑠+2
Demonstrate two ways of converting this model to a statevariable model in standard form
Solution
a.Divide the numerator and denominator of the 𝑇𝐹 by 𝑠
𝑍(𝑠) 5𝑠 + 3 5 + 3/𝑠
=
=
𝑈(𝑠)
𝑠+2
1 + 2/𝑠
The objective is to obtain a 1 in the denominator, which is
then used to isolate 𝑍(𝑠) as follows
2
3
1
𝑍 𝑠 = − 𝑍 𝑠 + 5𝑈 𝑠 + 𝑈 𝑠 = 3𝑈 𝑠 − 2𝑍 𝑠 + 5𝑈(𝑠)
𝑠
𝑠
𝑠
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

6


11/17/2012

System Dynamics


5.13

State Variable Models and Simulation Methods

§1. State Variable Models
The term within square brackets multiplying 1/𝑠 is the input
to an integrator, and the integrator’s output can be selected
as a state-variable 𝑥
𝑍 𝑠 = 𝑋(𝑠) + 5𝑈(𝑠)
1

𝑋 𝑠 ≡ 𝑠 3𝑈 𝑠 − 2𝑍 𝑠
1
= 3𝑈 𝑠 − 2 𝑋 𝑠 + 5𝑈 𝑠
𝑠
1
= [−2𝑋 𝑠 − 7𝑈(𝑠)]
𝑠
This gives 𝑥 = −2𝑥 − 7𝑢, with output equation 𝑧 = 𝑥 + 5𝑢
This fits the standard form
𝒙 = 𝑨𝒙 + 𝒃𝑢
𝒚 = 𝑪𝒙 + 𝑫𝑢
with 𝑨 = −2, 𝑩 = −7, 𝒚 = 𝑧, 𝑪 = 1, and 𝑫 = 5
where

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics


5.14

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models
b.Rewrite the transfer function in the form
𝑈(𝑠)
𝑍 𝑠 = (5𝑠 + 3)
𝑠+2
Define the state-variable 𝑥 as follows
𝑈(𝑠)
𝑋 𝑠 ≡
⟹ 𝑠𝑋 𝑠 = −2𝑋 𝑠 + 𝑈(𝑠)
𝑠+2
The state equation
𝑥 = −2𝑥 + 𝑢
To find the output equation, note that
𝑈 𝑠
𝑍 𝑠 = 5𝑠 + 3
= 5𝑠 + 3 𝑋 𝑠 = 5𝑠𝑋 𝑠 + 3𝑋(𝑠)
𝑠+2
⟹ 𝑍 𝑠 = 5 −2𝑋 𝑠 + 𝑈 𝑠 + 3𝑋 𝑠 = −7𝑋 𝑠 + 5𝑈(𝑠)
and the output equation
𝑧 = −7𝑥 + 5𝑢
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien


7


11/17/2012

System Dynamics

5.15

State Variable Models and Simulation Methods

§1. State Variable Models
- Example 5.1.6 Numerator Dynamics in a Second-Order System
Obtain a state-variable model for
𝑋 𝑠
4𝑠 + 7
= 2
𝑈 𝑠
5𝑠 + 4𝑠 + 7
Relate the initial conditions for the state variables to the given
initial conditions 𝑥(0) and 𝑥(0)
Solution
Divide by 5𝑠 2 to obtain a 1 in the denominator
4 −1 7 −2
𝑠 + 𝑠
𝑋 𝑠
5
= 5
4 −1 7 −2
𝑈 𝑠

1+ 𝑠 + 𝑠
5
5
Use the 1 in the denominator to solve for 𝑋(𝑠)
4
7
4
7
𝑋 𝑠 = 𝑠 −1 + 𝑠 −2 𝑈 𝑠 − 𝑠 −1 + 𝑠 −2 𝑋(𝑠)
5
5
5
5
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.16

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models
1 4
4
1 7
7
⟹𝑋 𝑠 = − 𝑋 𝑠 + 𝑈 𝑠 +
𝑈 𝑠 − 𝑋(𝑠)

𝑠
5
5
𝑠 5
5
This equation shows that 𝑋(𝑠) is the output of an integration.
Thus 𝑥 can be chosen as a state variable 𝑥1
𝑋1 𝑠 = 𝑋(𝑠)
The term within square brackets is the input to an integration,
and thus the second state variable can be chosen as
1 7
7
1 7
7
𝑋2 𝑠 =
𝑈 𝑠 − 𝑋(𝑠) =
𝑈 𝑠 − 𝑋1 (𝑠)
𝑠 5
5
𝑠 5
5
then
1 4
4
𝑋1 𝑠 = − 𝑋 𝑠 + 𝑈 𝑠 + 𝑋2 (𝑠)
𝑠
5
5

HCM City Univ. of Technology, Faculty of Mechanical Engineering


Nguyen Tan Tien

8


11/17/2012

System Dynamics

5.17

State Variable Models and Simulation Methods

§1. State Variable Models
The state equations
4
4
𝑥1 = − 𝑥1 + 𝑥2 + 𝑢
5
5
7
7
𝑥2 = − 𝑥1 + 𝑥2 + 𝑢
5
5
The output equation 𝑥 = 𝑥1
The standard form
𝒙 = 𝑨𝒙 + 𝒃𝑢
𝒚 = 𝑪𝒙 + 𝑫𝑢

where
4
4

1
5
𝑨=
,𝑩 = 5 ,𝑪 = 1 0 ,𝑫 = 0
7
7

0
5
5
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.18

Nguyen Tan Tien

State Variable Models and Simulation Methods

§1. State Variable Models

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien


9


11/17/2012

System Dynamics

5.19

State Variable Models and Simulation Methods

§1. State Variable Models
4.Transfer Function Versus State-Variable Models
- Both models are equally effective and equally easy to use
- The decision whether to use a transfer function model or a
state-variable model depends on many factors, including
personal preference
- Application of basic physical principles sometimes directly
results in a state-variable model
- If you need to obtain the step response as a function, it might
be easier to convert the model to transfer function form and
then use the Laplace transform to obtain the desired function

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.20

Nguyen Tan Tien


State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
1.Creation of transfer functions or conversion to transfer function
Function: tf(num,den)
Example
Model
5𝑥 + 7𝑥 + 4𝑥 = 𝑓(𝑡), or
𝑋(𝑠)
1
= 2
𝐹(𝑠) 5𝑠 + 7𝑠 + 4
Matlab sys1 = tf(1, [5, 7, 4])
𝑑3 𝑥

𝑑2 𝑥

𝑑𝑥

𝑑2 𝑓

𝑑𝑓

Model

8 𝑑𝑡 3 − 3 𝑑𝑡 2 + 5 𝑑𝑡 + 6𝑥 = 4 𝑑𝑡 2 + 3 𝑑𝑡 + 5𝑓(𝑡)

Matlab


sys2 = tf([4, 3, 5], [8, -3, 5, 6])

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

10


11/17/2012

System Dynamics

5.21

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
2.Creates state-space model or converts model to state space
Function: ss(A,B,C,D)
Example
Model
𝑥1 = 𝑥2
4
7
1
𝑥2 = − 𝑥1 − 𝑥2 + 𝑓 𝑡
5
5
5

Matlab

A = [0, 1; -4/5, -7/5];
B = [0; 1/5];
C = [1, 0];
D = 0;
sys3 = ss(A,B,C,D)

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.22

Nguyen Tan Tien

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
3.Quick access to state-space data
Function: ssdata(sys)
Example
Matlab [A, B, C, D] = ssdata(sys1)
4.Quick access to transfer function data
Function: tfdata(sys)
Example
Matlab tfsys3 = tf(sys3)
[num, den] = tfdata(sys3, 'v')

HCM City Univ. of Technology, Faculty of Mechanical Engineering


Nguyen Tan Tien

11


11/17/2012

System Dynamics

5.23

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
- Example 5.2.1
Transfer Functions of a Two-Mass System
Obtain the transfer functions 𝑋1 (𝑠)/𝐹(𝑠) and 𝑋2 (𝑠)/𝐹(𝑠) of the
state-variable model 𝒛 = 𝑨𝒛 + 𝒃𝑓, with
0
1
0
0
0
𝑥1
𝑧1
12
4
8
−1


0
𝑧2
𝑥1
5
5
5
𝒛= 𝑧 = 𝑥 ,𝑨=
,𝒃= 0
0
0
0
1
3
2
1
4
8
4
8
𝑧4
𝑥2


3
3
3
3
3
Solution

To derive the transfer functions for 𝑥1 and 𝑥2 , we must define
the 𝑪 and 𝑫 matrices to indicate that 𝑧1 and 𝑧3 are the output
variables 𝑦1 and 𝑦2
1 0 0 0
0
𝑪=
,𝑫=
0 0 1 0
0
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.24

Nguyen Tan Tien

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
Matlab A = [0,1,0,0;-1,-12/5,4/5,8/5;0,0,0,1;4/3,8/3,-4/3,-8/3];
B = [0; 0; 0; 1/3];
C = [1, 0, 0, 0; 0, 0, 1, 0];
D = [0; 0];
sys4 = ss(A, B, C, D);
tfsys4 = tf(sys4)

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien


12


11/17/2012

System Dynamics

5.25

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.26

Nguyen Tan Tien

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
5.Initial condition response of state-space models
Function: initial(sys, x0)
- Example 5.2.2
Free Response of the Two-Mass Model
Consider the state-variable model 𝒛 = 𝑨𝒛 + 𝒃𝑓, with

0
1
0
0
0
𝑥1
𝑧1
12
4
8
−1 − 5
0
𝑧2
𝑥1
5
5
𝒛= 𝑧 = 𝑥 ,𝑨=
,𝒃= 0
0
0
0
1
3
2
1
4
8
4
8
𝑧4

𝑥2


3

3

3

3

3

Compute the free response 𝑥1 (𝑡) for 𝑥1 0 = 5, 𝑥1 0 = −3,
𝑥2 0 = 4, 𝑥2 0 = 2

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

13


11/17/2012

System Dynamics

5.27

State Variable Models and Simulation Methods


§2. State Variable Methods with Matlab
- Solution
The initial condition in term of variable 𝑧
𝑧1 (0)
𝑥1 (0)
5
𝑧2 (0)
𝑥1 (0)
−3
𝒛(0) =
=
=
𝑧3 (0)
𝑥2 (0)
4
𝑧4 (0)
𝑥2 (0)
2
The output equation
𝒚 = 𝑪𝒛 + 𝑫𝑓 with 𝑪 = 1 0 0 0 , 𝑫 = 0
Matlab A = [0,1,0,0;-1,-12/5,4/5,8/5;0,0,0,1;4/3,8/3,-4/3,-8/3];
B = [0; 0; 0; 1/3];
C = [1, 0, 0, 0];
D = [0];
sys5 = ss(A, B, C, D);
initial(sys5, [5, -3, 4, 2])
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics


5.28

Nguyen Tan Tien

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
6.Impulse response of LTI models
Function: impulse(sys)
Example
Matlab impulse(sys1)
7.Step response of LTI models
Function: step(sys)
Example
Matlab step(sys1)
8.Simulate time response of LTI models to arbitrary inputs
Function: lsim(sys)
Example
Matlab t=0:0.01:2*pi; u=cos(t);
lsim(sys1, u, t)
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

14


11/17/2012


System Dynamics

5.29

State Variable Models and Simulation Methods

§2. State Variable Methods with Matlab
9.Convert roots to polynomial
Function: poly(A)
Example
Matlab A = [0, 1; -6, -5];
poly(A)

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.30

Nguyen Tan Tien

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
Numerical methods for solving differential equations
- Example 5.3.1
MATLAB Solution of 𝑦 = 𝑠𝑖𝑛𝑡
Use the ode45 solver for the problem 𝑦 = 𝑠𝑖𝑛𝑡, 𝑦 0 = 0 for
0 ≤ 𝑡 ≤ 4𝜋. The exact solution is 𝑦(𝑡) = 1 − 𝑐𝑜𝑠𝑡
Solution

• Create and save the function file, named sinefn.m
function ydot = sinefn(t,y)
ydot = sin(t);
• Matlab [t, y] = ode45(@sinefn, [0, 4*pi], 0);
y_exact = 1 - cos(t);
plot(t,y,'o',t,y_exact),xlabel('t'),ylabel('y(t)'),...
axis([0 4*pi -0.5 2.5])
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

15


11/17/2012

System Dynamics

5.31

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
- Example 5.3.2

A Rocket-Propelled Sled
A rocket-propelled sled on a track is
represented in the figure as a mass
𝑚 with an applied force 𝑓 that
represents the rocket thrust. The

rocket thrust initially is horizontal, but the engine accidentally
pivots during firing and rotates with an angular acceleration of
𝜃 = 𝜋/50𝑟𝑎𝑑/𝑠. Compute the sled’s velocity 𝑣 for 0 ≤ 𝑡 ≤ 6 if
𝑣(0) = 0. Rocket thrust is 4000𝑁 and the sled mass is 450𝑘𝑔
Solution
The sled’s equation of motion
450𝑣 = 4000𝑐𝑜𝑠𝜃(𝑡)
80
⟹𝑣=
𝑐𝑜𝑠𝜃(𝑡)
9

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.32

Nguyen Tan Tien

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
To obtain 𝜃(𝑡), note that
𝑡
𝑡
𝑡
𝜋
𝜋
𝜋 2

𝜃 = 𝜃 𝑑𝑡 =
𝑡 ⟹ 𝜃 = 𝜃 𝑑𝑡 =
𝑡𝑑𝑡 =
𝑡
50
100
0
0
0 50
The equation of motion becomes
80
𝜋 2
80 𝑡
𝜋 2
𝑣=
𝑐𝑜𝑠
𝑡 ⟹𝑣 𝑡 =
𝑐𝑜𝑠
𝑡 𝑑𝑡
9
100
9 0
100
• Create and save the function file, named sled.m
function vdot = sled(t,v)
vdot = 80*cos(pi*t^2/100)/9;
• Matlab [t,v] = ode45(@sled,[0 6],0);
plot(t,v,t,(80*t/9)),xlabel('t (s)'), ylabel('v (m/s)'),...
gtext('\theta = 0'),gtext('\theta \neq 0')
HCM City Univ. of Technology, Faculty of Mechanical Engineering


Nguyen Tan Tien

16


11/17/2012

System Dynamics

5.33

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
Using the ODE solvers to solve an equation of order 2 or greater
Consider the second-order equation 5𝑦 + 7𝑦 + 4𝑦 = 𝑓 𝑡
Define the state variable
𝑥1 ≡ 𝑥2
4
7
1
𝑥2 ≡ − 𝑥1 − 𝑥2 + 𝑓(𝑡)
5
5
5
• Create and save the function file, named example1.m
function xdot = example1(t,x)
xdot = [x(2); (1/5)*(sin(t)-4*x(1)-7*x(2))];
• Matlab [t, x] = ode45(@example1, [0, 6], [3, 9]);

plot(t,x)

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.34

Nguyen Tan Tien

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
- Example 5.3.3
A Nonlinear Pendulum Model
The pendulum shown in the figure consists of a
concentrated mass 𝑚 attached to a rod whose
mass is small compared to 𝑚. The rod’s length
is 𝐿. The equation of motion for this pendulum
𝑔
𝜃 + 𝑠𝑖𝑛𝜃 = 0
𝐿
Suppose that 𝐿 = 1𝑚 and 𝑔 = 9.81𝑚/𝑠 2 . Use Matlab to solve
this equation for 𝜃(𝑡) for two cases
• Case 1

𝜃(0) = 0.5𝑟𝑎𝑑, 𝜃(0) = 0

• Case 2


𝜃(0) = 0.8𝜋𝑟𝑎𝑑, 𝜃(0) = 0

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

17


11/17/2012

System Dynamics

5.35

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
Solution
Rewrite the pendulum equation
𝑥1 ≡ 𝜃 = 𝑥2
𝑔
𝑥2 ≡ 𝜃 = − 𝑠𝑖𝑛𝑥1 = −9.81𝑠𝑖𝑛𝑥1
𝐿
• Create and save the function file, named pendulum.m
function xdot = pendulum(t,x)
xdot = [x(2); -9.81*sin(x(1))];
• Matlab [ta, xa] = ode45(@pendulum, [0, 5], [0.5, 0]);
[tb, xb] = ode45(@pendulum, [0, 5], [0.8*pi, 0]);
plot(ta,xa(:,1),tb,xb(:,1)),xlabel('Time (s)'),...

ylabel('Angle (rad)'),gtext('Case 1'),gtext('Case 2')
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.36

Nguyen Tan Tien

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
Matrix method Matrix operations can be used to reduce the
number of lines to be typed in the derivative function file
Consider the mass-spring-damper model 𝑚𝑦 + 𝑐𝑦 + 𝑘𝑦 = 𝑓(𝑡)
Define 𝑥1 ≡ 𝑦, 𝑥2 ≡ 𝑦, the equation can be rewritten
𝑥1 = 𝑥2
𝑘
𝑐
1
𝑥2 = − 𝑥1 − 𝑥2 + 𝑓(𝑡)
𝑚
𝑚
𝑚
This can be written as one matrix equation as follows
0
1
0
𝑥1
𝑥1

1 𝑓(𝑡)
𝑘
𝑐
=
𝑥2 +
𝑥2


𝑚
𝑐
𝑚
In compact form this is𝒙 = 𝑨𝒙 + 𝑩𝑓(𝑡), where
0
1
0
𝑥1
𝑨 = −𝑘 − 𝑐 , 𝑩 = 1 , 𝑥 = 𝑥
2
𝑐

𝑚

𝑚

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

18



11/17/2012

System Dynamics

5.37

State Variable Models and Simulation Methods

§3. The Matlab ode Functions
• Create and save the function file, named msd.m
function xdot = msd(t,x)
m = 1; c = 2; k = 5; f = 10;
A = [0, 1;-k/m, -c/m];
B = [0; 1/m];
xdot = A*x+B*f;
• Matlab [t, x] = ode45(@msd, [0, 5], [0, 0]);
plot(t,x),xlabel('Time (s)'),...
ylabel('Displacement (m) and Velocity (m/s)'),...
gtext('Displacement'), gtext('Velocity')

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.38

Nguyen Tan Tien

State Variable Models and Simulation Methods


§3. The Matlab ode Functions

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

19


11/17/2012

System Dynamics

5.39

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
- Type simulink in the Matlab Command window to start
Simulink
- Create a new model

- Start to use …
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.40


Nguyen Tan Tien

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
1.Simulation Diagrams
- Simulink models is constructed using a diagram that shows
the elements of the problem to be solved. Such diagrams are
called simulation diagrams
- Consider the equation
𝑦 = 10𝑓(𝑡) ⟹ 𝑦 𝑡 =

10𝑓 𝑡 𝑑𝑡

which can be thought of as two steps, using an intermediate
variable 𝑥
𝑥 𝑡 = 10𝑓 𝑡 ,

𝑦 𝑡 =

HCM City Univ. of Technology, Faculty of Mechanical Engineering

𝑥 𝑡 𝑑𝑡

Nguyen Tan Tien

20


11/17/2012


System Dynamics

5.41

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
The summer is used to subtract as well as to sum variables
𝑧 =𝑥−𝑦

The summer symbol can be used to represent the equation
𝑦 = 𝑓 𝑡 − 10𝑦, which can be expressed as
𝑦 𝑡 =

or as

[𝑓 𝑡 − 10𝑦]𝑑𝑡

1
𝑦 = (𝑓 − 10𝑦)
𝑠

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.42

Nguyen Tan Tien


State Variable Models and Simulation Methods

§4. Simulink and Linear Models
- Example 5.4.1
Simulink Solution of 𝑦 = 10𝑠𝑖𝑛𝑡
Use Simulink to solve the following problem for 0 ≤ 𝑡 ≤ 13
𝑑𝑦
10𝑠𝑖𝑛𝑡,
𝑦 0 =0
𝑑𝑡
The exact solution is 𝑦 𝑡 = 10 1 − 𝑐𝑜𝑠𝑡
Solution
1.Start Simulink and open a new model window
2.Select and place the Sine Wave block from Sources
category (amplitude = 1, bias = 0, frequency = 1, phase =
0, sample time = 0)
3.Select and place the Gain block from the Math category
(gain value = 10)
4.Select and place the Integrator block from the Continuous
category (initial condition = 0)
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

21


11/17/2012


System Dynamics

5.43

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
5.Select and place the Scope block from the Sinks category
6.Connect the input port on each block to the outport port on
the preceding block
7.Click on the Simulation menu, and click the Configuration
Parameters item. Click on the Solver tab, and enter 13 for
the Stop time
8.Run the simulation by clicking on the Simulation menu, and
then clicking the Start item
9.There is a bell sound when the simulation is finished

HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.44

Nguyen Tan Tien

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
- Example 5.4.2
Exporting to the MATLAB Workspace

Demonstrate how to export the results of the simulation to
the Matlab workspace, where they can be plotted or
analyzed with any of the Matlab functions
Solution
Modify the Simulink model constructed in Example 5.4.1 with
refer to the figure

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

22


11/17/2012

System Dynamics

5.45

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
1.Delete the Scope block and the arrow connecting the Scope
block
2.Select and place the To Workspace block from the Sinks
category and the Clock block from the Sources category
3.Select and place the Mux block from the Signal Routing
category (number of inputs = 2)
4.Connect the top input port of the Mux block to the output port

of the Integrator block, connect the bottom input port of the
Mux block to the outport port of the Clock block
5.Specify variable name 𝑦 as the output. Specify the Save
Format as Array
6.After running the simulation, to plot 𝑦(𝑡), type in the MATLAB
Command window
plot(y(:,2),y(:,1)),xlabel('t'),ylabel('y')
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.46

Nguyen Tan Tien

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
- Example 5.4.3
Simulink Model for 𝑦 = −10𝑦 + 𝑓(𝑡)
Construct a Simulink model to solve
𝑦 = −10𝑦 + 𝑓 𝑡 ,
𝑦 0 =1
where 𝑓 𝑡 = 2𝑠𝑖𝑛4𝑡, for 0 ≤ 𝑡 ≤ 3
Solution
Simulink model for the problem

HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien


23


11/17/2012

System Dynamics

5.47

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
1.Modify the previous example by rearranging the blocks as
shown in the figure, need to add a Sum block
2.Select the place the Sum block from the Math operations
library, changing the sign of sum block to ±
3.To reverse the direction of the gain block, right-click on the
block, select Format from the pop-up menu, and select Flip
Block
4.Connect the negative input port of the Sum block to the
output port of the Gain block. Connect the input of the Gain
to the arrow connecting the Integrator and the Scope
5.Select Configuration Parameters from the Simulation menu,
and set the Stop time to 3
6.Run the simulation as before and observe the results in the
Scope
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics


5.48

Nguyen Tan Tien

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
2.Simulating State Variable Models
- Example 5.4.4
Simulink Model of a Two-Mass System
Consider the state-variable model of a two-mass system
𝒛 = 𝑨𝒛 + 𝒃𝑓, with
0
1
0
0
0
𝑥1
𝑧1
12
4
8
−1 − 5
0
𝑧2
𝑥1
5
5
𝒛= 𝑧 = 𝑥 ,𝑨=

,𝒃= 0
0
0
0
1
3
2
1
4
8
4
8
𝑧4
𝑥2


3

3

3

3

3

Develop a Simulink model to plot the unit-step response of
the variables 𝑥1 and 𝑥2 with the initial conditions 𝑥1 0 = 0.2,
𝑥1 0 = 0, 𝑥2 0 = 0.5, 𝑥2 0 = 0


HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

24


11/17/2012

System Dynamics

5.49

State Variable Models and Simulation Methods

§4. Simulink and Linear Models
- Solution
The matrices in the output equation 𝒚 = 𝑪𝒛 + 𝑫𝑓(𝑡)
1 0 0 0
0
𝑪=
,
𝑫=
0 0 1 0
0
1.Select and place Step block from the sources category
(step time = 0, initial value = 0, final value = 1, sample time = 0)
2.Select and place the State-Space block
(A = [0,1,0,0; -1,-12/5,4/5,8/5; 0,0,0,1; 4/3,8/3,-4/3,-8/3], B =
[0;0;0;1/3], C = [1,0,0,0; 0,0,1,0], D = [0; 0], initial conditions

= [0.2; 0; 0.5; 0])
3.Select and place the Scope block
4.Connect all blocks
5.Set stop time = 25. The plots of both 𝑥1 and 𝑥2 will appear
in the Scope
HCM City Univ. of Technology, Faculty of Mechanical Engineering

System Dynamics

5.50

Nguyen Tan Tien

State Variable Models and Simulation Methods

§5. Simulink and Non-Linear Models
- Example 5.5.1
Simulink Model of a Rocket-Propelled Sled
A rocket-propelled sled on a track is
represented in the figure as a mass
𝑚 with an applied force 𝑓 that
represents the rocket thrust. The
rocket thrust initially is horizontal, but the engine accidentally
pivots during firing and rotates with an angular acceleration of
𝜃 = 𝜋/50𝑟𝑎𝑑/𝑠. Compute the sled’s velocity 𝑣 for 0 ≤ 𝑡 ≤ 6 if
𝑣(0) = 0. Rocket thrust is 4000𝑁 and the sled mass is 450𝑘𝑔
Use Simulink to obtain the solution
a.Create a Simulink model to solve this problem, 0 ≤ 𝑡 ≤ 10𝑠
b.Now suppose that the engine angle is limited by a
mechanical stop to 600 . Create a Simulink model to solve

the problem
HCM City Univ. of Technology, Faculty of Mechanical Engineering

Nguyen Tan Tien

25


×