09: Add Koen's functions for task 3

This commit is contained in:
2022-03-08 16:03:55 +01:00
parent d647c705d0
commit 0533b7df32

View File

@ -388,7 +388,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 6,
"metadata": { "metadata": {
"deletable": false, "deletable": false,
"nbgrader": { "nbgrader": {
@ -406,16 +406,23 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"def phi_euler_modified(x, y, f, i):\n", "def phi_euler_modified(x, y, f, i):\n",
" # YOUR CODE HERE\n", " h = x[i]-x[i-1]\n",
" raise NotImplementedError()\n", " phi = f(x[i-1]+0.5*h, y[i-1]+0.5*h*f(x[i-1],y[i-1]))\n",
" return phi\n",
" \n", " \n",
"def phi_heun(x, y, f, i):\n", "def phi_heun(x, y, f, i):\n",
" # YOUR CODE HERE\n", " h = x[i]-x[i-1]\n",
" raise NotImplementedError()\n", " phi = 0.5*(f(x[i-1],y[i-1])+f(x[i-1]+h,y[i-1]+h*f(x[i-1],y[i-1])))\n",
" return phi\n",
" \n", " \n",
"def phi_rk4(x, y, f, i):\n", "def phi_rk4(x, y, f, i):\n",
" # YOUR CODE HERE\n", " h = x[i]-x[i-1]\n",
" raise NotImplementedError()" " k1 = f(x[i-1],y[i-1])\n",
" k2 = f(x[i-1]+0.5*h,y[i-1]+0.5*h*k1)\n",
" k3 = f(x[i-1]+0.5*h,y[i-1]+0.5*h*k2)\n",
" k4 = f(x[i-1]+h,y[i-1]+h*k3)\n",
" phi = (1/6)*(k1+2*k2+2*k3+k4)\n",
" return phi"
] ]
}, },
{ {