MATLAB provides a variety of techniques for solving dynamics problems numerically. Online
help for each of the commands shown below is available by typing help ‘command_name’ or
doc ‘command_name’ at the MATLAB prompt.
1 of 9
Simulating Dynamic Systems
– 2t
Suppose we find: y ( t ) = 8 – 5e ( sin ( 2πt ) + 0.5 cos ( 2πt ) )
Linear Systems:
There are three general purpose methods for solving dynamics problems; transfer function
method, state space integration method, and the MATLAB function lsim.
2 of 9
Simulating Dynamic Systems
2
s Y ( s ) – sy ( 0 ) – ẏ ( 0 ) + 2sY ( s ) – 2y ( 0 ) + 5Y ( s ) = 5U ( s ) + sU ( s ) + u ( 0 )
Let y(0) = 0 ẏ ( 0 ) = 0 u(0) = 0
s+5
Then 2
U (s)
Y ( s ) = 
s + 2s + 5
Let the input u(t) be the step function and to solve for y(t) do
1 s+5
With U ( s ) =  then Y ( s ) = 
2
s s ( s + 2s + 5 )
2
Let u(t) be sin(2t) and to solve for y(t) do U ( s ) = 
2

s +4
3 of 9
Simulating Dynamic Systems
Integration Method:
The integration method utilizes the state space representation of the system and the MATLAB
ode23 or the ode45 integrator. One advantage of this method is that it is much easier to incor
porate the initial conditions in the solution without having to find the new transfer function. Lets
look at the last example given above.
ẋ ( t ) = 0 1 x ( t ) + 0 u ( t ) ẋ = Ax + Bu
The state space representation is – 5 – 2 1
y = 5 1 x(t ) y = Cx + Du
To implement the model create the Mfile eqn1.m as shown
4 of 9
Simulating Dynamic Systems
5 of 9
Simulating Dynamic Systems
ẋ 1 0 1 x x
OR x1 = i x 2 = ẋ 1 = 1 R
1
+ 0 u y = 0 1 1
ẋ 2 –  –  x 2 1 L x2
LC L
With Matlab:
There is a corresponding function for discrete time dynamics for the functions mentioned above .
The function would start with a ‘d’ like dstep for example.
0.4673z – 0.3393
Suppose we find the ztransform to be G ( z ) = 
2
z – 1.5327z + 0.6607
Then
6 of 9
Simulating Dynamic Systems
Nonlinear Systems:
Nonlinear dynamics are solved by the integration method. The system equations are expressed in
state form described in a Mfile function and the ode integrators are used to solve for the state tra
jectories.
1
ẋ 1 =  [ – x 1 + x 2 – g ( x 2 ) ]
Consider the WienBridge Oscillator: C 1 R1
1 1
ẋ 2 =  [ – x 1 + x 2 – g ( x 2 ) ] –  x 2
C 2 R1 C 2 R2
3 5
g ( v ) = 3.234v – 2.195v + 0.666v
7 of 9
Simulating Dynamic Systems
M
Consider the Cart and Pendulum Problem x
2
( M + m )ẋ˙ + mlθ̇˙ cos θ – mlθ̇ sin θ = 0
l
2
ml θ̇˙ + mlẋ˙cos θ – mlẋθ̇ sin θ + mgl sin θ = 0 θ
m
Use a change of variables to y then we can write
y1 ẏ 1 y2
x(t ) 1 0 0 0
ẋ ( t ) y 0 ( M + m ) 0 ml cos y 3 ẏ 2 2
mly 4 sin y 3
= 2 ⋅ =
θ(t ) y3 0 0 1 0 ẏ 3 y4
2
θ̇ ( t ) y4 0 ml cos y 3 0 ml ẏ 4 ml ( y 2 y 4 – g ) sin y 3
8 of 9
Simulating Dynamic Systems
9 of 9