Game Development Reference
In-Depth Information
A = F / M;
V2 = V2 + A * (dt/2);
// Estimate the truncation error
et = absf(V1 − V2);
// Estimate a new step size
dtnew = dt * SQRT(eto/et);
if (dtnew < dt)
{ // take at step at the new smaller step size
F = (T − (C * V));
A = F / M;
Vnew = V + A * dtnew;
Snew = S + Vnew * dtnew;
} else
{ // original step size is okay
Vnew = V1;
Snew = S + Vnew * dt;
}
// Update old velocity and displacement with the new ones
V = Vnew;
S = Snew;
}
Better Methods
At this point, you might be wondering why you can't simply use more terms in the Taylor
series to reduce the truncation error of Euler's method. In fact, this is the basis for several
integration methods that offer greater accuracy than Euler's basic method for a given
step size. Part of the difficulty associated with picking up more terms in the Taylor's
series expansion is in being able to determine the second, third, fourth, and higher
derivatives of the function you're trying to integrate. The way around this problem is
to perform additional Taylor series expansions to approximate the derivatives of the
function under consideration and then substitute those values back into your original
expansion.
Taking this approach to include one more Taylor term beyond the basic Euler method
yields a so-called improved Euler method that has a reduced truncation error on the
order of (∆ t ) 3 instead of (∆ t ) 2 . The formulas for this method are:
k 1 = (∆t) y'(t, y)
k 2 = (∆t) y'(t + ∆t, y + k 1 )
y(t + ∆t) = y(t) + ½ (k 1 + k 2 )