We consider the problem of firing cannon balls: this involves two-dimensional motion in a gravitational field including air resistance. We set up Newton's equations for the x and y components of the motion.
g is the gravitational acceleration, and b the air drag coefficient. m is the mass of the ball. We assume the drag to be proportional to the velocity.
We set up Newton's equations as first-order differential equations for the momentum and position vector components (Hamilton's equation). In the x direction we have drag as the only force, while in the y direction gravity acts as well.
The initial conditions are specified through the parameters:
We can verify that the found solutions indeed satisfy the differential equations:
It is of interest to Taylor expand the solutions around t =0. This shows how the velocities begin to deviate from their inital values:
The change is linear in time, and depends in the drag part on the initial velocity components, while the contributions from gravity are obvious in the linear term. Note that the quadratic terms are more complicated.
It is of interest to investigate various aspects of the solution. The most common problem concerns the dependence of the trajectory on the inclination of the cannon for fixed drag coefficient b . Note that in real life one will include additional factors, such as the wind speed and direction.
In order to plot solutions we need to specify the parameters. In SI (MKSA) units we have
we pick a mass of 1 kg:
a drag coefficient (in kg/s):
Suppose we fix now the initial speed (by fixing the amount of powder for the firing of the cannon). We can still vary the inclination angle. How can we achieve this goal?
Again in SI units (in m/s):
We can choose a parameter for the inclination angle:
To generate functions rather than expressions we need the unapply command:
We are ready to integrate the equations for the position vector components. A dummy variable has to be used for the time integration ( s replacing t ). Again we use the unapply procedure to generate a mapping.
We have functions that generate the position vector for given inclination angle theta (in radians) and time t (in seconds). Thus, we can plot the trajectory parametrically (the help page ?plot includes an example for this plot mode):
The limits on the axes were adjusted by hand. If we wish to automate the process we can do this by finding the times at which the ball intercepts the surface.
This is done below.
As an exercise the reader may want to play around with the amount of friction. For a very small friction constant b the parabolic shape known from textbook solutions should be recovered.
The intercept with the surface is obtained from
Note that we cross y =0 at the beginning of the motion as well. The order in which the two solutions are found may vary. It does not matter for the parametric plot which way the trajectory is traced out. We do not need to specify the range on the axes, as they are automatically adjusted with the solution.
We graph a family of solutions in which the inclination of the cannon is changed. The objective is to determine the range, and to observe the maximum height reached by the projectile.
We set up a color table to be able to distinguish the solutions.
> for i from 1 to imax do:
> P[i]:=plot([X(theta,t),Y(theta,t),t=t0..t0],color=coltab[i]): od:
We can also display the sequence of graphs as an animation:
An interesting extension is to vary the air drag as a function of the height. The air density falls off exponentially with increased height. The numerical solution of the generalized equation of motion which include a height-dependent air drag coefficient are discussed in N. Giordano's book Computational Physics (Prentice-Hall 1997).