"**Task 2:** Modify the above program to produce a plot of the ratio of final kinetic energy to initial kinetic energy against lauch angle θ in the range $0 \\to 90^{\\circ}$. Your program should prompt for :\n",
"**Task 2:** Modify the above program to produce a plot of the ratio of final kinetic energy to initial kinetic energy against lauch angle θ in the range $0 \\to 90^{\\circ}$. Your program should prompt for :\n",
"\n",
"\n",
...
@@ -82,10 +82,10 @@
...
@@ -82,10 +82,10 @@
"\n",
"\n",
"### Checkpoint\n",
"### Checkpoint\n",
"\n",
"\n",
"- To help you with this checkpoint we've already provided you with a program skeletong structure below.\n",
"- To help you with this checkpoint we've already provided you with a program skeleton structure below.\n",
"- Test your program with the following conditions: \n",
"- Test your program with the following conditions: \n",
"- Call a demonstrator, show them your code, and run your programs for the two different conditions.\n",
"- Call a demonstrator, show them your code, and run your programs for the two different conditions.\n",
"\n",
"\n",
"### Assessment\n",
"### Assessment\n",
...
...
%% Cell type:markdown id:abaa6e4a tags:
%% Cell type:markdown id:abaa6e4a tags:
## Checkpoint 5
## Checkpoint 5
### Aim
### Aim
To write two Python programs to numerically analyse the path of a projectile under gravity and drag force. There are two tasks, one to display the trajectory and the second to display the relation between final kinetic energy and launch angle.
To write two Python programs to numerically analyse the path of a projectile under gravity and drag force. There are two tasks, one to display the trajectory and the second to display the relation between final kinetic energy and launch angle.
### Numerical Integration
### Numerical Integration
In this checkpoint we will use the simplest numerical integration technique called First Order Euler. This involves iteratively calculating the position and velocity at a set of times $t_i$=iΔt for i=0,1,2,… where we assume that the position and velocity at time $t_{i+1}$ depend only on the position and velocity at time $t_i$. In particular if at time $t_i$ the particle has
In this checkpoint we will use the simplest numerical integration technique called First Order Euler. This involves iteratively calculating the position and velocity at a set of times $t_i$=iΔt for i=0,1,2,… where we assume that the position and velocity at time $t_{i+1}$ depend only on the position and velocity at time $t_i$. In particular if at time $t_i$ the particle has
$$\text{Position} = \vec{x}_i$$
$$\text{Position} = \vec{x}_i$$
$$\text{Velocity} = \vec{v}_i$$
$$\text{Velocity} = \vec{v}_i$$
$$\text{Acceleration} = \vec{a}_i$$
$$\text{Acceleration} = \vec{a}_i$$
then at time $t_{i+1}=t_i+Δt$ the position and velocity of the particle can be approximated by
then at time $t_{i+1}=t_i+Δt$ the position and velocity of the particle can be approximated by
$$\vec{x}_{i+1} = \vec{x}_i+Δt\vec{v}_i$$
$$\vec{x}_{i+1} = \vec{x}_i+Δt\vec{v}_i$$
$$\vec{v}_{i+1} = \vec{v}_i+Δt\vec{a}_i$$
$$\vec{v}_{i+1} = \vec{v}_i+Δt\vec{a}_i$$
So if we start at time $t_0=0$ at position $\vec{x}_0$ and velocity $\vec{v}_0$, then provided we can calculate the force on the particle, and hence the acceleration $\vec{a}_i$, and use small enough time steps Δt, we can iteratively trace out the path by repeated use of the above relations.
So if we start at time $t_0=0$ at position $\vec{x}_0$ and velocity $\vec{v}_0$, then provided we can calculate the force on the particle, and hence the acceleration $\vec{a}_i$, and use small enough time steps Δt, we can iteratively trace out the path by repeated use of the above relations.
### Forces on Particle
### Forces on Particle


If we consider a particle of mass m travelling with velocity $\vec{v}$ subject to gravity and drag from a fluid as shown below, then the drag force is given by
If we consider a particle of mass m travelling with velocity $\vec{v}$ subject to gravity and drag from a fluid as shown below, then the drag force is given by
$$ \vec{F}_d=−\frac{1}{2}\rho AC_Dv^2\hat{v}$$
$$ \vec{F}_d=−\frac{1}{2}\rho AC_Dv^2\hat{v}$$
where $\rho$ is the density of the fluid, A is the cross-sectional area of the particle, $C_D$ is the drag coefficient and $\hat{v}=\vec{v}/|v|$, being the unit vector in the direction of the velocity.
where $\rho$ is the density of the fluid, A is the cross-sectional area of the particle, $C_D$ is the drag coefficient and $\hat{v}=\vec{v}/|v|$, being the unit vector in the direction of the velocity.
Thus the acceleration of of the particle is given by $\vec{a}=\frac{1}{m}\vec{F}_d−g\hat{j}$ where g is acceleration due to gravity, being 9.81 $ms^{−2}$. We can write this as:
Thus the acceleration of of the particle is given by $\vec{a}=\frac{1}{m}\vec{F}_d−g\hat{j}$ where g is acceleration due to gravity, being 9.81 $ms^{−2}$. We can write this as:
$$ \vec{a} =−\beta v^2\hat{v}−g\hat{j}$$
$$ \vec{a} =−\beta v^2\hat{v}−g\hat{j}$$
where $\beta=\frac{\rho AC_D}{2m}$, where $\beta$ is the normalised drag coefficient for the system.
where $\beta=\frac{\rho AC_D}{2m}$, where $\beta$ is the normalised drag coefficient for the system.
In this problem the position, velocity and acceleration are all two dimensional vectors so they have a horizontal and vertical component that you have to treat separately in the calculation.
In this problem the position, velocity and acceleration are all two dimensional vectors so they have a horizontal and vertical component that you have to treat separately in the calculation.
So in terms of components in x (horizontal) and y (vertical) we can write:
So in terms of components in x (horizontal) and y (vertical) we can write:
where the components of acceleration from the above equations are:
where the components of acceleration from the above equations are:
$a_x=−\beta vv_x$ and $a_y=−\beta vv_y−g$
$a_x=−\beta vv_x$ and $a_y=−\beta vv_y−g$
where v is the magnitude of the velocity, so being $v=\sqrt{v^2_x+v^2_y}$
where v is the magnitude of the velocity, so being $v=\sqrt{v^2_x+v^2_y}$
### Task
### Task
**Task 1:** Write a Python program to plot out the trajectory of a projectile starting at position $\vec{x}_0=(0,0)$ for specified initial velocity and normalised drag coefficient. You program should prompt for
**Task 1:** Write a Python program to plot out the trajectory of a projectile starting at position $\vec{x}_0=(0,0)$ for specified initial velocity and normalised drag coefficient. You program should prompt for
- Magnitude of the initial velocity $v_0$ in $ms^{−1}$.
- Magnitude of the initial velocity $v_0$ in $ms^{−1}$.
- Angle θ from the horizontal of initial velocity in degrees.
- Angle θ from the horizontal of initial velocity in degrees.
- β the normalised drag coefficient.
- β the normalised drag coefficient.
- Δt the step interval in seconds.
- Δt the step interval in seconds.
The path should be traced and displayed using Matplotlib from the inital starting position until the particle re-crosses the x-axis. Your graph should have a suitable title and axis labels. Your program should also print the range of the projectile to the terminal.
The path should be traced and displayed using Matplotlib from the inital starting position until the particle re-crosses the x-axis. Your graph should have a suitable title and axis labels. Your program should also print the range of the projectile to the terminal.
**Task 2:** Modify the above program to produce a plot of the ratio of final kinetic energy to initial kinetic energy against lauch angle θ in the range $0 \to 90^{\circ}$. Your program should prompt for :
**Task 2:** Modify the above program to produce a plot of the ratio of final kinetic energy to initial kinetic energy against lauch angle θ in the range $0 \to 90^{\circ}$. Your program should prompt for :
- Initial velocity $v_0$.
- Initial velocity $v_0$.
- Normalised drag coefficient $\beta$.
- Normalised drag coefficient $\beta$.
- Timestep $\Delta t$.
- Timestep $\Delta t$.
and plot out, using Matplotlib, a graph of $K_f / K_i$ against $\theta$.
and plot out, using Matplotlib, a graph of $K_f / K_i$ against $\theta$.
### Checkpoint
### Checkpoint
- To help you with this checkpoint we've already provided you with a program skeletong structure below.
- To help you with this checkpoint we've already provided you with a program skeleton structure below.
- Test your program with the following conditions:
- Test your program with the following conditions: