{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Assignment 2\n",
"\n",
"## **Your name here** (**Your student number here**)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This assignment is due on **Monday, March 11th**, at noon. You need to submit the `ipynb` file via Quercus. If you are unsure how to submit the assignment, please check before the deadline. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This assignment guides you through the steps of building a numerical model of a chaotic system, the driven damped pendulum. We will discuss what chaos is and how we can understand it from an analytical point of few later in the course. Here, you will approach this topic from a numerical point of view."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The equation of motion for the driven, damped pendulum is\n",
"$$\\ddot{\\phi} + 2\\beta \\dot \\phi +\\omega_0^2 \\sin \\phi = F(t),$$\n",
"where $\\omega_9$ is the natural frequency of the pendulum, $\\beta$ is the damping parameter, and $F(t)$ is an external driving force."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 1\n",
"\n",
"Rewrite this second order differential equation as two coupled first order equations:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\\frac{d^2\\phi}{dt^2} = ... $$\n",
"$$\\frac{d\\phi}{dt} = ... $$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, define a vector $\\mathbf{y}$ and then rewrite the above equations as a vector equation:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\\frac{d\\mathbf{y}}{dt} = \\begin{pmatrix} ...\\\\...\\end{pmatrix}$$\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 2\n",
"\n",
"Complete the implementation of the function $f(\\mathbf{y},t)$ that takes the vector $\\mathbf{y}$ and the current time $t$ as an argument and returns the derivative of $\\mathbf{y}$. You may assume that the external force $F$ is periodic and has the form\n",
"$$F(t) = \\gamma \\omega_0^2 \\cos(\\omega t),$$\n",
"where the constant $\\gamma$ describes the driving amplitude and $\\omega$ the driving frequency. Note that this is a case where you need to make use of thr $t$ argument of the right hand side function."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def f(y,t,beta,omega0,gamma,omega):\n",
" dydt = np.zeros(2)\n",
" ...\n",
" return dydt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 3\n",
"\n",
"Complete the code in the following cell to integrate the problem with the scipy ``odeint`` function over the interval from $t=0$ to $t=2\\pi$ with 1000 sample points along the way."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from scipy.integrate import odeint"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# initial conditions\n",
"y0 = np.array([0,0]) \n",
"# parameters\n",
"omega = 2*np.pi\n",
"omega0 = 1.5*omega\n",
"gamma = 0.2\n",
"beta = omega0/4.\n",
"# setup sample points\n",
"t = np.linspace( ... )\n",
"# do the actual integration\n",
"sol = odeint( ... )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 4\n",
"\n",
"Create a plot with the position $\\phi$ as a function of time. Add labels to the axes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"ax.plot( ... )\n",
"..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 5\n",
"\n",
"The pendulum in the last part settles into a periodic motion after a few cycles. Next, rerun the simulation from above and change $\\gamma$ to 1.073 and integrate from $t=0$ to $t=30$ time units. As above, plot $\\phi$ as a function of time. Also, create a second plot, where you zoom in to the region $x \\in [20,30]$ and $y \\in [-8.8,-7.8]$. Describe what you observe!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 6\n",
"\n",
"Finally, rerun the simulation with $\\gamma=1.105$ from $t=0$ to $t=100$ and plot $\\phi$ versus time. What you will see is a chaotic system with no signs of periodicity. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}