Week 9 Labview: "Numerical Solution of A Second-Order Linear Ode"
Week 9 Labview: "Numerical Solution of A Second-Order Linear Ode"
MAE-170
May 18, 2015
Assignment 6
Numerical Solution of a 2nd-order, Linear ODE
1 P ROBLEM S TATEMENT
d 2x
dx
+ c + kx = 0
2
dt
dt
x(t = 0 ) = x *
dx
(t = 0 ) = 0
dt
Figure 1.1: Model of the physical system for this weeks assignment.
the mass of the box, k is the spring constant, and c is the viscous damping coefficient of
ot. The variable x is the displacement
of the mass
from
and the
is only
a
For this assignment,
you
willequilibrium,
be simulating
dynamics
of the simple spring-masstime. This physical system is realized in numerous different applications for example,
damper
system
as
shown
in
Figure
1.
The
equation
of
motion
governing
this system in the
bile shock absorbers and, coincidentally, is the physical analogue of a PD control
k
c conditions
with
initial
othe
= following
=
m,
2 m o
!x! + 2 o x! + o x = 0
d 2x
dx
+c
+ kt = 0
2
dt
dt
x(t = 0) = x
dx
(t = 0) = 0 linear,
t over the x denotes differentiation with respect to time. This is adsecond-order,
t
ous, ordinary differential equation with constant coefficients. A simple way to
y solve ODEs of order higher than one is to transform the single equation into a system
er ODEs. Defining the vector
& y # & x#
y = $$ 1 !! = $$ !!
% y 2 " % x! " ,
d & y1 # & 0
$ !=$
dt $% y 2 !" $% o2
1 #& y1 # & g1 #
!$ ! = $ !
2 o !"$% y2 !" $% g 2 !"
conditions:
& x *#
y = $$ !!
%0"
ow employ two integration schemes to numerically march this system of first-order ODEs
(1.1)
(1.2)
(1.3)
Here, m is the mass, k is the spring constant, and c is the viscous damping coefficient
of the dash dashpot. The variable x is the displacement of the mass from equilibrium, and is
only a function of time. This physical system is realized in numerous different applications for example in the physical analogue of a PD control system.
Defining the un-damped angular frequency 0 and the damping ratio as
k
c
0 =
, =
m
2m0
we can re-write the equation of motion in the form
x + 20 x + 20 x = 0
(1.4)
where a dot over the x denotes differentiation with respect to time. This is a second-order,
linear, homogeneous, ordinary differential equation with constant coefficients. A simple way
to numerically solve ODEs of order higher than one is to transform the single equation into a
system of first-order ODEs. Defining the vector
(
y =
) ( )
y1
x
=
,
y2
x
( ) ( )
d y
y1
x
=
=
y2
x
dt
(1.5)
1
20
(
x
y =
0
](
) ( )
y1
g1
=
y2
g2
(1.6)
)
(1.7)
We may now employ two integration schemes to numerically march this system of firstorder ODEs through time. The first is the Explicit Euler method, which is defined by
yn = yn1 + h f1 = yn1 + h g ( yn1 , t n1 )
(1.8)
The second method we are going to use is a second-order Runge-Kutta (RK2) scheme, which
is defined as
[(
)
]
1
1
yn = yn1 + h 1
f1 +
f2
2c
2c
f1 = g ( yn1 , t n1 )
(1.9)
( )
(
)
h
h
f2 = g yn1 +
f , t n1 +
(1.10)
c
c
where, y n represents the next value of y to which we are marching, and y n1 is the previously
computed value of y. We are using a value of 2 for the constant c. This syntax may seem
daunting, however it is relatively straight forward. The process is delineated in the following
pseudo-code, from which you are to base your program.
f1 = g ( y n 1 , t n 1 )
,
,h)
f 2 = g ** y n 1 + * ' f , t n 1 +
+c(
+
h)
'
c '(
Here, yn represents the next value of y to which we are marching, and yn-1 is the previouslycomputed value of y. We are using a value of 2 for the constant c. This syntax may seem daunting,
so the process is delineated in the following pseudo-code, from which you are to base your program:
h = 0.01;
% this is the time-step we are using, in seconds
L = 0.1;
% this is the damping ratio (arbitrarily assigned)
omega = 20; % this is the un-damped natural frequency (arbitrarily assigned)
x(0) = 50; % this is the initial displacement of the mass, x*
dx(0) = 0; % this is the initial velocity of the mass, 0
for i = 1:round(5/h)
f_1
= dx(i-1);
f_2
= -x(i-1)*omega^2 2*L*omega*dx(i-1);
You will need to access the previous iteration values of x and d x. There is a special
A screenshot
a working
program
with these
the given
values
is shown
below:
LabVIEWofartifact
used
to acquire
that
we have
covered
in previous assignments.
Helpful Concepts:
Sequence Structure
A sequence structure carries out a sequence of events. There are two types of sequence structures: flat and
stacked. In a flat structure, as shown in the block diagram, there are multiple frames which execute in a
2 H ELPFUL C ONCEPTS
2.1 S EQUENCE S TRUCTURE
A sequence structure carries our a sequence of events. There are two types of sequence
structures: flat and stacked. In a flar structure, as shown in the block diagram, there are
multiple frames that execute in a left-to-right sequential order. Code within the first frame
will execute completely. After it is finished, the program moves onto the next frame, and so
on.
A stacked structure works in the same way, except you only see one frame at a time,
much like the event structure. There is a text ox at the top of the loop that will tell you which
frame you are on.
To add or delete a frame in either structure, simply-right click the border of the loop and
choose the corresponding option. You can add a sequence either before or after the frame
you are currently on.