Commit 9febb211 authored by Éamonn Murray's avatar Éamonn Murray

Minor text fixes

parent 004b31cc
......@@ -3,9 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
......@@ -54,9 +52,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def euler(x0, xprime, h, tmax):\n",
......@@ -75,7 +71,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
......@@ -85,10 +80,10 @@
" return x*np.cos(t)\n",
"\n",
"# And compare the result for different step sizes.\n",
"t1, x1 = euler(1, v1, 0.5, 20)\n",
"t2, x2 = euler(1, v1, 0.2, 20)\n",
"t3, x3 = euler(1, v1, 0.1, 20)\n",
"t4, x4 = euler(1, v1, 0.001, 20)\n",
"t1, x1 = euler(x0=1, xprime=v1, h=0.5, tmax=20)\n",
"t2, x2 = euler(x0=1, xprime=v1, h=0.2, tmax=20)\n",
"t3, x3 = euler(x0=1, xprime=v1, h=0.1, tmax=20)\n",
"t4, x4 = euler(x0=1, xprime=v1, h=0.001, tmax=20)\n",
"plt.plot(t1, x1, label=\"dt=0.4\")\n",
"plt.plot(t2, x2, label=\"dt=0.2\")\n",
"plt.plot(t3, x3, label=\"dt=0.1\")\n",
......@@ -137,9 +132,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# The Euler method can be unstable.\n",
......@@ -179,9 +172,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def x_newton(xi, xprime, t, h):\n",
......@@ -205,9 +196,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Let's see if this solves the stability issue we had before:\n",
......@@ -228,7 +217,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
......@@ -270,9 +258,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def RK2(x0, xprime, h, tmax):\n",
......@@ -291,9 +277,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"t1, x1 = RK2(1, v1, 1.0, 20)\n",
......@@ -353,9 +337,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def RK4(x0, xprime, h, tmax):\n",
......@@ -379,9 +361,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"t1, x1 = RK4(1, v1, 1.0, 20)\n",
......@@ -400,7 +380,7 @@
"source": [
"## Implicit RK\n",
"\n",
"As with the backward Euler, there many implicit Runge-Kutta methods also exist. In the explict methods discussed so far the value of the solution at the current step is determined solely by the information from the previous steps. As with the forward Euler method, this can lead to stability issues unless the step size is small enough for certain types of systems. The implicit methods alleviate this, as we saw with the backward Euler method. In the implicit methods, a system of equations must be solved at each step, so these tend to be somewhat slower."
"As with the backward Euler, many implicit Runge-Kutta methods also exist. In the explict methods discussed so far the value of the solution at the current step is determined solely by the information from the previous steps. As with the forward Euler method, this can lead to stability issues unless the step size is small enough for certain types of systems. The implicit methods alleviate this, as we saw with the backward Euler method. In the implicit methods, a system of equations must be solved at each step, so these tend to be somewhat slower."
]
},
{
......@@ -434,9 +414,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"sp_res = scipy.integrate.solve_ivp(fun=v1, t_span=(0, 20), y0=[1], method='RK45')\n",
......@@ -446,9 +424,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"plt.plot(sp_res.t, sp_res.y[0], \"ro\", label=\"SciPy RK45\")\n",
......@@ -460,13 +436,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Say we want to find the values at specific times, we can\n",
"# pass an array of t -values to the t_eval argument.\n",
"# pass an array of t-values to the t_eval argument.\n",
"tvalues = np.linspace(0, 20, 100)\n",
"\n",
"sp_res2 = scipy.integrate.solve_ivp(fun=v1, t_span=(0, 20),\n",
......@@ -481,9 +455,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Or if we want some general dense output, there's\n",
......@@ -533,9 +505,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def damped_oscillator(t, y, gamma, omega0):\n",
......@@ -556,9 +526,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Then we can use this with SciPy as follows\n",
......@@ -616,9 +584,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def leapfrog(accel, x0, v0, dt, nt):\n",
......@@ -660,9 +626,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Let's test this for an atom moving in a quartic potential.\n",
......@@ -733,9 +697,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def verlet(accel, x0, v0, dt, nt):\n",
......@@ -776,9 +738,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Find the trajectory using our verlet function for\n",
......@@ -821,9 +781,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def velocityverlet(accel, x0, v0, dt, nt):\n",
......@@ -874,9 +832,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Find the trajectory using our velocity-verlet function for\n",
......@@ -1003,9 +959,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def fe_tise(V, x0, x1, nx, mass, ):\n",
......@@ -1034,9 +988,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Let's see what we get for a quartic potential\n",
......@@ -1077,7 +1029,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
"version": "3.7.1"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
......
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