diff --git a/Week 6/10 Hyperbolic PDEs.ipynb b/Week 6/10 Hyperbolic PDEs.ipynb index b43f192..f029c25 100644 --- a/Week 6/10 Hyperbolic PDEs.ipynb +++ b/Week 6/10 Hyperbolic PDEs.ipynb @@ -39,7 +39,7 @@ "cell_type": "raw", "metadata": {}, "source": [ - "team_members = \"\"" + "team_members = \"Koen Vendrig, Kees van Kempen\"" ] }, { @@ -66,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "deletable": false, "nbgrader": { @@ -83,10 +83,7 @@ }, "outputs": [], "source": [ - "# Import packages here ...\n", - "\n", - "# YOUR CODE HERE\n", - "raise NotImplementedError()" + "import numpy as np" ] }, { @@ -183,8 +180,31 @@ "outputs": [], "source": [ "def pdeHyperbolic(a, x, t, f, g):\n", - " # YOUR CODE HERE\n", - " raise NotImplementedError()" + " # TODO: Docstring.\n", + " \n", + " n = len(t)\n", + " m = len(x)\n", + " \n", + " # TODO: The stepsize is defined by fixed h (k), but the input x (t)\n", + " # could allow variable step size. What should it be?\n", + " #h = x[1] - x[0]\n", + " l = x[-1]\n", + " h = l/(m - 1)\n", + " k = t[1] - t[0]\n", + " λ = a*k/h\n", + " \n", + " A = np.eye(m - 2)*2*(1 - λ**2) + ( np.eye(m - 2, m - 2, 1) + np.eye(m - 2, m - 2, -1) )*λ**2\n", + " \n", + " w = np.zeros((n, m))\n", + " \n", + " # Set initial values w[i, 0] = f[x[i]] and w[i, 1] = ...\n", + " # TODO: Fix previous comment.\n", + " w[:, 0] = f(x)\n", + " # TODO: What does the length of x[1:]?\n", + " w[:, 1] = (1 - λ**2)*f[x[1:m - 1]] + λ**2/2*f(x[2:m]) - λ**2/2*f(x[2:m]) + k*g(x[1:m - 1])\n", + " \n", + " for j in range(2, n):\n", + " w[:, j] = " ] }, { @@ -441,7 +461,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" },