# Ordinary Differential Equations

Exercise 8.7: Trajectory with air resistance
Many elementary mechanics problems deal with the physics of objects moving or flying through the air, but they almost always ignore friction and air resistance to make the equations solvable. If weāre using a computer, however, we donāt need solvable equations.
Consider, for instance, a spherical cannonball shot from a cannon standing on level ground. The air resistance on a moving sphere is a force in the opposite direction to the motion with magnitude

$F = \frac{1}{2} \pi R^2\rho C v^2,$

where R is the sphereās radius, Ļ is the density of air, v is the velocity, and C is the so-called coefficient of drag (a property of the shape of the moving object, in this case a sphere).

1. Starting from Newtonās second law, F = ma, show that the equations of motion for the position (x, y) of the cannonball are

$\ddot{x} = - {\pi R^2\rho C\over2m}\, \dot{x}\sqrt{\dot{x}^2+\dot{y}^2},$
$\ddot{y} = - g - {\pi R^2\rho C\over2m}\, \dot{y}\sqrt{\dot{x}^2+\dot{y}^2},$

where m is the mass of the cannonball, g is the acceleration due to gravity, and $\dot{x}$ and $\ddot{x}$ are the first and second derivatives of x with respect to time.

2. Change these two second-order equations into four first-order equations using the methods you have learned, then write a program that solves the equations for a cannonball of mass 1 kg and radius 8 cm, shot at 30Āŗ to the horizontal with initial velocity 100 msā1. The density of air is Ļ = 1.22 kg mā3 and the coefficient of drag for a sphere is C = 0.47. Make a plot of the trajectory of the cannonball (i.e., a graph of y as a function of x).
3. When one ignores air resistance, the distance traveled by a projectile does not depend on the mass of the projectile. In real life, however, mass certainly does make a difference. Use your program to estimate the total distance traveled (over horizontal ground) by the cannonball above, and then experiment with the program to determine whether the cannonball travels further if it is heavier or lighter. You could, for instance, plot a series of trajectories for cannonballs of different masses, or you could make a graph of distance traveled as a function of mass. Describe briefly what you discover.

Exercise 8.4:
Building on the results from Example 8.6 above, calculate the motion of a nonlinear pendulum as follows.

1. Write a program to solve the two first-order equations, Eqs. (8.45)

${d\theta \over dt} = \omega$

and (8.46)

${d\omega \over dt} = -\frac{g}{l}\sin{\theta}$,

using the fourth-order RungeāKutta method for a pendulum with a 10 cm arm. Use your program to calculate the angle Īø of displacement for several periods of the pendulum when it is released from a standstill at Īø = 179Ā° from the vertical. Make a graph of Īø as a function of time.

2. Extend your program to create an animation of the motion of the pendulum. Your animation should, at a minimum, include a representation of the moving pendulum bob and the pendulum arm. (Hint: You will probably find the function rate discussed in Section 3.5 useful for making your animation run at a sensible speed. Also, you may want to make the step size for your RungeāKutta calculation smaller than the frame-rate of your animation, i.e., do several RungeāKutta steps per frame on screen. This is certainly allowed and may help to make your calculation more accurate.)For a bigger challenge, take a look at Exercise 8.15 on page 398, which invites you to write a program to calculate the chaotic motion of the double pendulum.