Game Development Reference

In-Depth Information

16.4 Ordinary Differential Equations

In this section, we study methods for numerically solving first-order ordinary

differential equations. We can always write such equations in the form

′

()

(

)

y

xf

=

xy

,

,

(16.58)

where
f
is a function that we are able to evaluate for any given values of
x
and
y
.

Most differential equations encountered in a physical simulation are second-order

or higher, but we will be able to show that the ability to solve first-order equa-

tions also gives us the ability to solve equations of any order by writing them as a

system of first-order equations.

16.4.1 Euler's Method

Euler's method
is an extremely simple technique for approximating values of the

solution

()

y x
to the differential equation given by Equation (16.58). Coupled

with this simplicity is low accuracy, so we describe Euler's method now only as

an introduction to later discussions of more effective methods.

()

Suppose that we know an initial state

y x

=

y

, and we wish to approxi-

0

0

mate the value of the function
y
at

x

=+

xh

, where
h
is some small step size.

0

()

Writing the derivative

′

x

as a finite difference, Equation (16.58) becomes

y

0

(

)

yx

h
+−
=

h

y

0

0

(

)

f

xy

,

.

(16.59)

(

)

Solving for

y xh

+

, we have

0

(

)

(

)

y xhy f

+= +

xy

,

.

(16.60)

0

0

(

)

(

(

)

)

This gives us the state

from which the process can be

repeated. The general formula for Euler's method is thus

x

,

y

=+

x

h y x

,

+

h

11

0

0

=+

=+

xh

x

i

+

1

i

(

)

y

y f

xy

,

.

(16.61)

i

+

1

i

i

i

Let us consider as an example a projectile moving under the influence of

gravity. Its equation of motion is

′

()

y

t

=−

v t

,

(16.62)

0

Search Nedrilad ::

Custom Search