0% found this document useful (0 votes)
199 views

Week 9 Labview: "Numerical Solution of A Second-Order Linear Ode"

1. The document describes a numerical simulation of a spring-mass-damper system using LabVIEW. 2. The system is modeled by a second-order linear ordinary differential equation, which is converted to a system of first-order equations and discretized using Euler and Runge-Kutta integration schemes. 3. The LabVIEW program implements these schemes to simulate the system over 5 seconds, with the spring constant, damping ratio, and time step as adjustable parameters.

Uploaded by

Michael Li
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
199 views

Week 9 Labview: "Numerical Solution of A Second-Order Linear Ode"

1. The document describes a numerical simulation of a spring-mass-damper system using LabVIEW. 2. The system is modeled by a second-order linear ordinary differential equation, which is converted to a system of first-order equations and discretized using Euler and Runge-Kutta integration schemes. 3. The LabVIEW program implements these schemes to simulate the system over 5 seconds, with the spring constant, damping ratio, and time step as adjustable parameters.

Uploaded by

Michael Li
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

U NIVERSITY OF C ALIFORNIA , S AN D IEGO

D EPARTMENT OF M ECHANICAL AND A EROSPACE E NGINEERING

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

signment, you will be simulating the dynamics of the


ng-mass-damper system as shown in the figure on the
e equation of motion governing this system in the
ection is given, along with the initial conditions, by:

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

vertical direction is given by,

he un-damped angular frequency !o and the damping ratio " asm

k
c conditions
with
initial
othe
= following
=
m,
2 m o

rite the equation of motion in the form:


2

!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! " ,

dy & y!1 # & x! #


=$ !=$ !
dt $% y! 2 !" $% !x!!"

resent the system in state-space form:

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)

and we can now represent the system in state-space form


( ) [
d y1
0
=
20
d t y2
with the initial conditions

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);

x(i) = x(i-1) + h*f_1;


dx(i) = dx(i-1) + h*f_2;
end
x_euler = x;
x(0) = 50; % re-defining the initial conditions
dx(0) = 0;
for i = 1:round(5/h)
f_11 = dx(i-1);
f_12 = -x(i-1)*omega^2 2*L*omega*dx(i-1);
f_21 = dx(i-1) + (h/2)*f_12;
f_22 = -(x(i-1)+(h/2)*f_11)*omega^2 2*L*omega*(dx(i-1)+(h/2)*f_12);

x(i) = x(i-1) + 0.75*h*f_11 + 0.25*h*f_21;


dx(i) = dx(i-1) + 0.75*h*f_12 + 0.25*h*f_22;
end
x_rk2 = x;
plot x_euler;
plot x_rk2;
The parameters h, L and omega should be controls on your front panel, so that you may visualize
Figure
1.2: Example
of pseudo-code
for we
thisare
weeks
assignment.
Theforparameters
h, L,soand
the effect
of changing
them. Note that
simulating
this system
5 seconds, and
the
number of
oncontrols
the for-loop
defined
as panel,
the closest
integer
value
tovisualize
(5/h).
iterations
should be
on isyour
front
so that
you
may
the effect of
changing them. Note that we are simulating this system for 5 seconds, and so the
HINTS:
number of iterations on the for-loop is defined as the closest inter value to h5 .
You will need to access the previous iteration values of x and dx. There is a special
LabVIEW artifact used to acquire these that we have covered in a previous homework
1.1
HINTS
Make sure Autoscale is enabled for
your
y-axis.

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.

Make sure Autoscale is enables for your y-axis.

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.

2.2 F ORMULA N ODE


A formula node provides a simple way to perform a lengthy calculation. For example, if
you want to compute a 10-term polynomial, it is probably a better idea to use one of these
instead of connecting a web of multiplication and division functions. To create an input or
output, simply right-click on the edge of the formula node and choose the option. Refer to
Help to learn the syntax of a Formula Node (right-click on the outside of the loop and choose
Help).

You might also like