09: Concept 7
This commit is contained in:
@ -730,7 +730,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
@ -747,8 +747,38 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
"def ODEF(x, y):\n",
|
||||
" # TODO: Docstring.\n",
|
||||
" return np.array([y[1], -np.sin(y[0])])\n",
|
||||
"\n",
|
||||
"h = .02\n",
|
||||
"x = np.arange(0, 2, h)\n",
|
||||
"y = (x + 1)**2 - 0.5*np.exp(x)\n",
|
||||
"eta = np.zeros(len(x))\n",
|
||||
"\n",
|
||||
"fig = plt.figure(figsize=(12, 8))\n",
|
||||
"gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1])\n",
|
||||
"\n",
|
||||
"ax0 = plt.subplot(gs[0])\n",
|
||||
"ax0.plot(x, y, label=\"exact solution\")\n",
|
||||
"ax0.set_yscale(\"log\")\n",
|
||||
"ax0.set_title(\"Solutions to $y' = y - x^2 + 1.0$\")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"ax1 = plt.subplot(gs[1])\n",
|
||||
"ax1.set_ylabel(\"$\\delta(x) = |\\~y(x) - y(x)|$\")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for alg, alg_name in algos:\n",
|
||||
" eta = integrator(x, y0, ODEF, alg)\n",
|
||||
" ax0.plot(x, eta, label=alg_name)\n",
|
||||
" ax1.plot(x, np.abs(eta - y), label=alg_name)\n",
|
||||
"\n",
|
||||
"ax0.legend()\n",
|
||||
"plt.xlabel(\"x\")\n",
|
||||
"ax0.set_ylabel(\"y(x)\")\n",
|
||||
"ax1.legend()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user