This homework builds on the skeleton code to be found here:
The assignment consists of three parts:
Transform the set of equations
For realistic, long-range artillery, a significant effect consists of the inclusion of the effect of the air density on the drag effect, i.e. the resistance the air offers to the projectile. It is well-known that the density changes with altitude, making it a function of $y$ in our problem. The simplest approximation is to treat the atmosphere as an isothermal ideal gas, assuming that its temperature is constant. The pressure $p$ then depends on the altitude,
It is clear that with sufficiently large $y$ differences between
these two approximations become apparent.
However, in both cases the drag force is proportional to the
air density, leading effectively to a drag force that depends not only
on velocity but also on the altitude:
To quantify these differences, add both versions of the correction factor to the class "Cannonball". It is a good idea to add them in such a way that the original version of the drag force is multiplied with the result of a corresponding method, and to have two different methods. This has already been done, with obvious empty methods as place holders. To make this accessible for marking an input choice of altitude dependence after the input of the drag coefficient such that the answer "const" corresponds to no altitude dependence, "isothermal" refers to the isothermal approximation, and "adiabatic" refers to the adiabatic approximation. You'll find that this choice is already implemented as a place holder in the program from the lecture.
Start from the DEq_Solver class for the evaluation of first order differential equations and supplement methods for solutions employing the Runge-Kutta methods of order 2 and 4. To this end, use the equations in the section on Runge-Kutta methods, keeping in mind that the x now are vectors, $x\to\underline x$.
Check that the results obtained with both methods converge
to the same trajectory by decreasing the step size from 0.1
down to 0.001.
To facilitate this a switch between the methods is provided selecting
"RK2" for the second-order Runge-Kutta, "RK4" for the fourth-order Runge-Kutta,
and "Euler" for the Euler method, respectively.
You will need to modify the "solve" method in the DEq_Solver class to accomodate a condition to stop the stepping not in $t$ but in $\underline x$, in particular its $y$-component. The solve function accepts an optional argument, "positive_index" to indicate which component of $\underline x$ should be checked. For example, with "positive_index=3" the while-loop should interrupt as soon as $\underline{x}[3]$ turns negative. This first negative point should still be recorded.
Fill the interpolate method in Interpolator.py. It takes a value $x$, a left pair $x_i,f(x_i)$ and a right pair $x_{i+1},f(x_{i+1})$, where $x_i < x < x_{i+1}$. The function should return the linearly interpolated value $f(x)$ between these two points.
Fill the $f$ function in Interpolator.py, The Interpolator class takes two same-length lists in the constructor, one with the $x_i$ values and one with the matching $f(x_i)$ values to be interpolated. The function should return $f(x)$ over the full range of these input lists.
Use the interpolator to implement the range() function in Cannonball. It should return the point along x where the height becomes zero again.