Game Development Reference
In-Depth Information
Table 7-1. Exact solution versus Euler solution
Time (s)
Velocity, exact (m/s)
Velocity, Euler (m/s)
Error
6.5
9.559084
9.733158
1.82%
7
10.06829
10.2465
1.77%
7.5
10.55267
10.73418
1.72%
8
11.01342
11.19747
1.67%
8.5
11.4517
11.63759
1.62%
As you can see, the truncation error in this example isn't too bad. It could be better,
though, and we'll show you some more accurate methods in a moment. Before that,
however, you should notice that in this example Euler's method is also stable—that is,
it converges well with the exact solution as shown in Figure 7-4 , where we've carried
the time range out further.
Figure 7-4. Convergence
Here's a code snippet that implements Euler's method for this example:
// Global Variables
float T; // thrust
float C; // drag coefficient
float V; // velocity
float M; // mass
float S; // displacement
.
.
.
// This function progresses the simulation by dt seconds using
 
Search Nedrilad ::




Custom Search