13 NUMERICAL SOLUTION OF ODE’S
28
13 Numerical Solution of ODE’s
In simulating dynamical systems, we frequently solve ordinary diﬀerential equations. These
are of the form
dx
=
f
(
t,x
)
,
dt
where the function
f
has as arguments both time and the state
x
. The time argument
is used if the system is timedependent (timevarying), but unnecessary if the system is
timeinvariant. Solving the diﬀerential equation means propagating
x
forward in time from
some initial condition, say
x
(
t
= 0), and typically the solution will be given as a vector of
[
x
(0)
,x
(Δ
t
)
,x
(2Δ
t
)
,
···
], where Δ
t
is a ﬁxed time step.
The Taylor series is used to derive most of the simple formulas for solving ODE’s. The
general Taylor series expansion of the generic function
g
in two variables is
g
(
t
+ Δ
t,x
+ Δ
x
) =
g
(
t,x
) +
∂g
∂t
Δ
t
+
∂g
∂x
Δ
x
+
1
2!
∂
2
g
∂t
2
Δ
t
2
+
1
2!
∂
2
g
∂t∂x
Δ
t
Δ
x
+
1
2!
∂
2
g
∂x∂t
Δ
x
Δ
t
+
1
2!
∂
2
g
∂x
2
Δ
x
2
+
···
.
In the above formula, when the arguments of g and its derivatives are not shown, we mean
that it is to be evaluated at (
t,x
), that is
g
alone means
g
(
t,x
) and so on. We use this
shorthand below in several places. The simplest of all the ODE methods is
forward Euler
,
created by setting
g
=
x
and looking only at the ﬁrst two terms on the righthand side of
the Taylor series:
x
(
t
+ Δ
t
) =
x
(
t
) +
dx
dt
Δ
t
=
x
(
t
) + Δ
tf
This formula says that
x
at the next time instant is the current
x
plus the time step times
the slope
evaluated at the current
x
. Referring to the Taylor series, we see that the forward
Euler does not do anything with the secondorder terms (Δ
t
2
and beyond), and so we say the
method is secondorder accurate in the step, which will turn out to be ﬁrstorder accurate
when you solve a real problem with many steps. Firstorder means that if you halve the
time step, you can expect about half the error in the overall simulation.
An alternative, the RungeKutta methods are popular workhorses, and implemented in the
MATLAB commands
ode23()
and
ode45()
. Let’s take a look at the ﬁrst of these: The rule
is
k
1
= Δ
tf
k
2
= Δ
tf
(
t
+ Δ
t/
2
,x
(
t
) +
k
1
/
2)
x
(
t
+ Δ
t
) =
x
(
t
) +
k
2
We see that
k
1
is the same change in
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '05
 GeorgeKocur
 Taylor Series, Euler, Runge–Kutta methods, Numerical Solution, Forward Euler

Click to edit the document details