Commit 52aa979a authored by Éamonn Murray's avatar Éamonn Murray

Fix some typos

parent 9febb211
......@@ -3,7 +3,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
......@@ -52,7 +54,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def euler(x0, xprime, h, tmax):\n",
......@@ -71,6 +75,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
......@@ -132,7 +137,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# The Euler method can be unstable.\n",
......@@ -160,11 +167,11 @@
"\n",
"The backward Euler method is a small modification of the forward Euler method given by\n",
"\n",
"$$ x_{n+1} = x_n + f(t_{n_1+1}, x_{n+1})h$$\n",
"$$ x_{n+1} = x_n + f(t_{n+1}, x_{n+1})h$$\n",
"\n",
"This will eliminate the stability problem mentioned above, but our equation is now implicit. This method is sometimes referred to as the implicit Euler method for this reason. We'll need to solve an equation for $x_{n+1}$ at each timestep, which will make this approach much more time consuming.\n",
"\n",
"This could be done, for example with one of the root finding methods covered before to solve $ x_{n+1} - x_n - f(t_{n_1+1}, x_{n+1})h= 0 $ for $x_{n+1}$.\n",
"This could be done, for example with one of the root finding methods covered before to solve $ x_{n+1} - x_n - f(t_{n+1}, x_{n+1})h= 0 $ for $x_{n+1}$.\n",
"\n",
"Let's write a simple Python implementation, using Newton's method."
]
......@@ -172,7 +179,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def x_newton(xi, xprime, t, h):\n",
......@@ -196,7 +205,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Let's see if this solves the stability issue we had before:\n",
......@@ -217,6 +228,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
......@@ -258,7 +270,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def RK2(x0, xprime, h, tmax):\n",
......@@ -277,7 +291,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"t1, x1 = RK2(1, v1, 1.0, 20)\n",
......@@ -337,7 +353,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def RK4(x0, xprime, h, tmax):\n",
......@@ -361,7 +379,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"t1, x1 = RK4(1, v1, 1.0, 20)\n",
......@@ -414,7 +434,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sp_res = scipy.integrate.solve_ivp(fun=v1, t_span=(0, 20), y0=[1], method='RK45')\n",
......@@ -424,7 +446,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"plt.plot(sp_res.t, sp_res.y[0], \"ro\", label=\"SciPy RK45\")\n",
......@@ -436,7 +460,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Say we want to find the values at specific times, we can\n",
......@@ -455,7 +481,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Or if we want some general dense output, there's\n",
......@@ -505,7 +533,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def damped_oscillator(t, y, gamma, omega0):\n",
......@@ -526,7 +556,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Then we can use this with SciPy as follows\n",
......@@ -584,7 +616,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def leapfrog(accel, x0, v0, dt, nt):\n",
......@@ -626,7 +660,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Let's test this for an atom moving in a quartic potential.\n",
......@@ -697,7 +733,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def verlet(accel, x0, v0, dt, nt):\n",
......@@ -738,7 +776,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Find the trajectory using our verlet function for\n",
......@@ -781,7 +821,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def velocityverlet(accel, x0, v0, dt, nt):\n",
......@@ -832,7 +874,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Find the trajectory using our velocity-verlet function for\n",
......@@ -959,7 +1003,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def fe_tise(V, x0, x1, nx, mass, ):\n",
......@@ -988,7 +1034,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Let's see what we get for a quartic potential\n",
......@@ -1029,7 +1077,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.5.3"
},
"toc": {
"base_numbering": 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment