{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Complex variable method for approximation of derivative"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compute derivative of\n",
"$$\n",
"f(x) = \\sin(x)\n",
"$$\n",
"at $x=2\\pi$ using the complex variable method\n",
"$$\n",
"\\frac{\\textrm{imag } f(x+ih)}{h}\n",
"$$\n",
"for $h=10^{-1},10^{-2},\\ldots,10^{-14}$."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'svg'\n",
"from numpy import sin,arange,zeros,pi,abs,imag\n",
"from matplotlib.pyplot import loglog,xlabel,ylabel"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" return sin(x)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1.66750020e-03 1.66667500e-05 1.66666675e-07 1.66666658e-09\n",
" 1.66666680e-11 1.66755498e-13 1.55431223e-15 2.22044605e-16\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00]\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"