Problem A: Ballistic Motion Given a location of a gun at (0,0,0), write an 3D artillery
simulator that can take in the mass of the projectile, amount of powder, the azimuth and elevation of
the gun barrel. Use the amount of powder and the mass of the projectile to determine the muzzle
velocity. Account for gravity and air friction. Assume that one kilogram of powder produces 10,000
newtons of force. Assume instantaneous acceleration as a result of the powder going off. Air friction
coefficient is constant. Set it to be 50 kg/s initially. The gun and target are both on the X-Z
plane.
Analysis: For analysis part, without loss of generality, we consider the condition without air friction for simplicity. The accumulate distances errors at time 10 sec and computation time for 500 * Δt are shown as follows, which are generated by Euler, 2nd Order Runge-Kutta, 4th Order Runge-Kutta Method in different time steps.
Distance Error | Euler | RK2 | RK4 |
Δt = 0.001 | 0.025925 | 0.023148 | 0.023117 |
Δt = 0.01 | 0.491989 | 0.001846 | 0.001846 |
Δt = 0.1 | 4.899979 | 0.000031 | 0.000031 |
Computation Time(μs) | Euler | RK2 | RK4 |
Δt = 0.001 | 81 | 190 | 532 |
Δt = 0.01 | 89 | 211 | 565 |
Δt = 0.1 | 67 | 157 | 444 |
Problem B: Spring-Mass Simulator A spring hands vertically in its equilibrium or resting
position. Given a user-defined mass m attached to the spring with the spring constant k, not stretched
at first. Simulate the motion of the spring and mass under the effects of spring and gravitational
forces. Assume the mass is 5 kg and k = 15kg∕s2. Then, set the mass to be 10 kg and k = 20kg∕s2.
Analysis: Without loss of generality, we consider the condition without damping for simplicity. The accumulate distances errors at time 10 sec and computation time for 500 * Δt are shown as follows, which are generated by Euler, 2nd Order Runge-Kutta, 4th Order Runge-Kutta Method in different time steps.
Distance Error | Euler | RK2 | RK4 |
Δt = 0.001 | 0.001997 | 0.000023 | 0.000000 |
Δt = 0.01 | 0.015499 | 0.002834 | 0.000002 |
Δt = 0.01 | 1.970125 | 0.283945 | 0.000417 |
Computation Time(μs) | Euler | RK2 | RK4 |
Δt = 0.001 | 54 | 135 | 428 |
Δt = 0.01 | 56 | 139 | 400 |
Δt = 0.1 | 64 | 128 | 402 |
Summary: Euler Method is much more efficient, but also generate much more errors and is more unstable than the other ones. 4th-Order Runge-Kutta Method is more accurate than 2nd-Order one(Mid Point), while need more computation time than 2nd-Order(Mid Point).