{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Error in finite difference approximation of derivative"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compute derivative of\n",
"$$\n",
"f(x) = \\sin(x)\n",
"$$\n",
"at $x=2\\pi$ using finite difference\n",
"$$\n",
"\\frac{f(x+h) - f(x)}{h}\n",
"$$\n",
"for $h=10^{-1},10^{-2},\\ldots,10^{-14}$."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'svg'\n",
"from numpy import sin,arange,zeros,pi,abs\n",
"from matplotlib.pyplot import loglog,xlabel,ylabel"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" return sin(x)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"