"where ω0 is known as the natural frequency of the undamped oscillator.\n",
"where ω$_0$ is known as the natural frequency of the undamped oscillator.\n",
"\n",
"\n",
"The solutions to this equation take the following forms:\n",
"The solutions to this equation take the following forms:\n",
"\n",
"\n",
...
...
%% Cell type:markdown id:ed4c83c4 tags:
%% Cell type:markdown id:ed4c83c4 tags:
## Checkpoint 3
## Checkpoint 3
### Background:
### Background:
The damped simple harmonic oscillator satisfies the second order differential equation
The damped simple harmonic oscillator satisfies the second order differential equation
$m\ddot{x} +b \dot{x} + kx=0$ where m is the mass of the oscillator, b is the coefficient of damping, and k is the spring constant.
$m\ddot{x} +b \dot{x} + kx=0$ where m is the mass of the oscillator, b is the coefficient of damping, and k is the spring constant.
Defining new constants
Defining new constants
$\gamma$=b/m and $\omega_0^2$=k/m
$\gamma$=b/m and $\omega_0^2$=k/m
we can re-write the differential equations as:
we can re-write the differential equations as:
$\ddot{x} + \gamma \dot{x} + \omega_{0}^2x =0 $
$\ddot{x} + \gamma \dot{x} + \omega_{0}^2x =0 $
where ω0 is known as the natural frequency of the undamped oscillator.
where ω$_0$ is known as the natural frequency of the undamped oscillator.
The solutions to this equation take the following forms:
The solutions to this equation take the following forms:
$ x=exp(−γt/2)[acosh(pt)+bsinh(pt)] $ when $ γ>2ω_0 $ with $ p^2=(γ^2/4)−ω^2_0 $
$ x=exp(−γt/2)[acosh(pt)+bsinh(pt)] $ when $ γ>2ω_0 $ with $ p^2=(γ^2/4)−ω^2_0 $
$ x=exp(−γt/2)[a+bt] $ when $ γ=2ω_0 $
$ x=exp(−γt/2)[a+bt] $ when $ γ=2ω_0 $
$ x=exp(−γt/2)[acos(ωt)+bsin(ωt)] $ when $ γ<2ω_0 $ with $ ω^2=ω^2_0−(γ^2/4)$
$ x=exp(−γt/2)[acos(ωt)+bsin(ωt)] $ when $ γ<2ω_0 $ with $ ω^2=ω^2_0−(γ^2/4)$
where these three conditions are known as over damped, critically damped and under damped respectively.
where these three conditions are known as over damped, critically damped and under damped respectively.
Note: Read these equations very carefully and note the locations of the parentheses.
Note: Read these equations very carefully and note the locations of the parentheses.
With the initial conditions that x=1 and $\dot{x}$ =0 at t=0 the above constants, after some manipulation, become,
With the initial conditions that x=1 and $\dot{x}$ =0 at t=0 the above constants, after some manipulation, become,
a=1 b=$\gamma$/2p when $\gamma$>2ω$_0$
a=1 b=$\gamma$/2p when $\gamma$>2ω$_0$
a=1 b=$\gamma$/2 when $\gamma$=2ω$_0$
a=1 b=$\gamma$/2 when $\gamma$=2ω$_0$
a=1 b=$\gamma$/2ω when $\gamma$<2ω$_0$
a=1 b=$\gamma$/2ω when $\gamma$<2ω$_0$
### Task
### Task
Write an interactive Python program to compute and display, using the pyplot function from Matplotlib, the solution for x against t for t in the range 0$\to 5\pi/ω_0$. Your program should:
Write an interactive Python program to compute and display, using the pyplot function from Matplotlib, the solution for x against t for t in the range 0$\to 5\pi/ω_0$. Your program should:
- Ask for and read in the values of ω$_0$, $\gamma$ and the number of points to plot on the graph from the terminal.
- Ask for and read in the values of ω$_0$, $\gamma$ and the number of points to plot on the graph from the terminal.
- Use a function of form shm(omega_zero,gamma,t) to calculate the displacement.
- Use a function of form shm(omega_zero,gamma,t) to calculate the displacement.
- Calculate and plot the amplitude and time to lists
- Calculate and plot the amplitude and time to lists
- Plot the output via pyplot with suitable title and labels to axis
- Plot the output via pyplot with suitable title and labels to axis
"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",
...
...
%% Cell type:markdown id:abaa6e4a tags:
%% Cell type:markdown id:abaa6e4a tags:
## Checkpoint 5
## Checkpoint 5
### 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
$Position = \vec{x}_i$
$Position = \vec{x}_i$
$Velocity = \vec{v}_i$
$Velocity = \vec{v}_i$
$Acceleration = \vec{a}_i$
$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.81ms$^{−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.81ms$^{−2}$. We can write this as:
$$ \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.
$$ \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.
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$.