From e7f95b0d7bcd87a6f995b06f8cc639818ded3576 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Mon, 11 Oct 2021 23:55:57 +0100 Subject: [PATCH 1/2] Fix a fencepost / off-by-one error The `myfieldline` function previously produced an sequence of N datapoints, but N points describe a chain of only N-1 lines. This means the actual distance the field lines cover is `distance / N * (N - 1)` not `distance`. --- 01-ExamplesPaper1-Field-Lines.ipynb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/01-ExamplesPaper1-Field-Lines.ipynb b/01-ExamplesPaper1-Field-Lines.ipynb index f5953f3..8a5ce29 100644 --- a/01-ExamplesPaper1-Field-Lines.ipynb +++ b/01-ExamplesPaper1-Field-Lines.ipynb @@ -123,25 +123,25 @@ " N = 100\n", " ds = float(distance) / N\n", " \n", - " X = np.zeros(N)\n", - " Y = np.zeros(N)\n", - " Z = np.zeros(N)\n", + " X = np.zeros(N+1)\n", + " Y = np.zeros(N+1)\n", + " Z = np.zeros(N+1)\n", " \n", " X[0] = x0\n", " Y[0] = y0\n", " Z[0] = z0\n", " \n", - " for i in range(1,N):\n", - " [Bx,By,Bz] = myfield( X[i-1], Y[i-1], Z[i-1] ) # Evaluate the field at the previous point (i-1)\n", + " for i in range(N):\n", + " [Bx,By,Bz] = myfield( X[i], Y[i], Z[i] ) # Evaluate the field at the previous point i\n", " # Normalise the vector:\n", " magnitude = np.sqrt( Bx**2 + By**2 + Bz**2 )\n", " Bnx = Bx / magnitude\n", " Bny = # insert your code\n", " Bnz = # insert your code\n", - " # Now evaluate the field line location at the current point (i)\n", - " X[i] = X[i-1] + Bnx*ds\n", - " Y[i] = # insert your code\n", - " Z[i] = # insert your code\n", + " # Now evaluate the field line location at the current point (i+1)\n", + " X[i+1] = X[i] + Bnx*ds\n", + " Y[i+1] = # insert your code\n", + " Z[i+1] = # insert your code\n", " \n", " return X, Y, Z # Return the coordinates of the field line" ] From 66f455f1cf5d283500fc7ed6828ccdc31dc6fa9d Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Mon, 11 Oct 2021 23:57:07 +0100 Subject: [PATCH 2/2] Add a comment --- 01-ExamplesPaper1-Field-Lines.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/01-ExamplesPaper1-Field-Lines.ipynb b/01-ExamplesPaper1-Field-Lines.ipynb index 8a5ce29..33aaace 100644 --- a/01-ExamplesPaper1-Field-Lines.ipynb +++ b/01-ExamplesPaper1-Field-Lines.ipynb @@ -123,6 +123,7 @@ " N = 100\n", " ds = float(distance) / N\n", " \n", + " # To create N line segments, we need N+1 points", " X = np.zeros(N+1)\n", " Y = np.zeros(N+1)\n", " Z = np.zeros(N+1)\n",