Game Development Reference
In-Depth Information
dv
m
x
=−
μ
v
kx
(4.25)
x
dt
dx
dt =
v
(4.26)
x
In Equation (4.25), the derivative of v x is a function of v x and x . In Equation (4.26), the
derivative of x is a function of v x . Because the solution of v x as a function of time depends on
x and the solution of x as a function of time depends on v x , the two equations are said to be
coupled and must be solved simultaneously by the ODE solver. The ODE solver will compute the
velocity, v x , and the location, x , at discrete time increments.
Most of the ODEs that we will solve in this topic will be higher-order ODEs that will first be
expanded into a set of first-order ODEs before they are solved.
Boundary Conditions
Solving an ODE requires more than just knowing the form of the differential equation. Also
required are things called boundary conditions , values of the dependent variables either at the
beginning or end of whatever range the ODE is being solved over. For example, if the flight of a
bullet is being modeled, boundary conditions might include the initial velocity and location of
the bullet as it leaves the gun barrel. Generally speaking, an ODE has an infinite number of
possible solutions. Specifying boundary conditions “pins down” the solution to the one that
we want.
An ODE where initial conditions for all the dependent variables are defined is called an
initial value problem . The Runge-Kutta solver solves this type of ODE by successively incre-
menting the independent variable, a process known as “marching,” updating the values of the
dependent variables every step of the way. All of the ODEs that we will encounter in this topic
will be initial value problems.
Sometimes initial values are not available for all of the dependent variables. Instead, the
values of some dependent variables may be defined at the end of the range of interest. For
example, you might want to specify the location of an object at one time and the velocity of the
object at a later time. This situation is referred to as a two-point boundary problem and is
generally more difficult to solve than an initial value problem.
One way to solve a two-point boundary problem is to make guesses for the initial values of
those dependent variables for which initial conditions aren't available. The ODE is integrated
and then it is determined whether the boundary conditions at the end of the range of interest
are met. If they aren't, another guess is made for the initial conditions, and the procedure repeats
itself over and over until the boundary conditions at the end of the range of interest are satisfied.
This technique is known as shooting .
Programming the Fourth-Order Runge-Kutta Solver
We now have all the information we need to write a program that will implement a fourth-order
Runge-Kutta ODE solver that will solve initial value problem-type ODEs. The solver will be
written as general as possible so that it will be able to solve any number of coupled first-order
ODEs. Two classes are needed to implement the ODE solver—the solver itself and a class that
represents the ODE to be solved.
 
Search WWH ::




Custom Search