The starting point for the implementation of this problem and its
solution in the form of a computer code is the following set of equations
Main program
In the main program, the steering unit, the following tasks will
have to be fulfilled:
- Input the parameters of the program.
- Initialise the class "Cannonball", encapsulating the
physics problem and the class "DEq_Solver" for the actual
calculation.
- Use the latter to solve the differential equation and produce
results.
- Store and plot the results.
- Initialise the class "Interpolator" and estimate the range of
the shot with it.
|
Initialisation of the physics problem
(encapsulated in the class "Cannonball")
The following parameters etc. need to be read in:
- $v_0$, the muzzle velocity,
- $\theta$, the firing angle,
- $B/m$, the drag coefficient of the projectile,
- $\delta t$, the timestep size, which again is a
parameter of the calculartion and not of the physics.
We assume that g is fixed by $g = 9.81 {\rm m/s}^2$.
Also, fix the initial conditions:
- $t_0=0$,
- $x_0=y_0=0$,
- $v_x = v_0\cos\theta$ and $v_y = v_0\sin\theta$.
|
Calculation: Solution of a general differential equation
of first order (encapsulated in the class "DEq_Solver")
The calculation amounts to the following algorithm:
- Repeat the time steps outlined below with size
Δt until $y_{i+1}\le 0$.
- In each time step:
- calculate $t_{i+1} = t_i+\Delta t$;
- calculate the components of the acceleration due to the
air drag force:
$\underline a_{\rm drag} =
\frac{\underline F_{\rm drag}}{m} =
-\frac{B_{\rm drag}}{m} v_i\underline v_i$,
using the velocity components of the step before.
- employ the equations above to update positions and
velocities:
\[\begin{eqnarray*}
x_{i+1} &=& x_i+v_{x,i}\Delta t\\
y_{i+1} &=& y_i+v_{y,i}\Delta t\\
v_{x,i+1} &=& v_{x,i}+a_{drag,x}\Delta t\\
v_{y,i+1} &=& v_{y,i}-g\Delta t+a_{drag,x}
\end{eqnarray*} \]
- calculate the absolute value of the (updated)
velocity $v_{i+1}$;
- store the time, positiions, and velocities.
It should be noted that, in principle, this is already provided
in your class DEq_Solver, the only thing neccessary is to
realise that the components of the positions and velocities
form a vector $\underline x = (x,y,v_x,v_y)$
(stick to exactly this sequence!) and to provide a
corresponding function $\underline f$ in the class "Cannonball".
|
Range estimate
A simple linear interpolation for the range of shot should be
sufficient.
To this end, we interpolate between $y_{i+1}$, the first point
where $y<0$, and $y_i$, the last point were $y>0$ yielding
\[ x_\mathrm{range}\,\approx\,
\frac{x_i+rx_{i+1}}{1+r}\, , \,\,\,\,\,
r=-y_i/y_{i+1} \, . \]
Of course, here $y_{\rm range}=0$.
|