{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Function $\\omega_N(x)$ arising in interpolation error"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For a given set of points $x_0, x_1, \\ldots, x_N \\in [-1,+1]$ we plot the function\n",
"$$\n",
"\\omega_N(x) = (x-x_0)(x-x_1) \\ldots (x-x_N), \\qquad x \\in [-1,+1]\n",
"$$\n",
"for uniform and chebyshev points."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'svg'\n",
"from numpy import linspace,pi,cos\n",
"from matplotlib.pyplot import plot,legend,grid,title"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def omega(x,xp):\n",
" f = 1.0\n",
" for z in xp:\n",
" f = f * (x-z)\n",
" return f"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"M = 1000\n",
"xx = linspace(-1.0,1.0,M)\n",
"\n",
"N = 16\n",
"xu = linspace(-1.0,1.0,N+1) # uniform points\n",
"xc = cos(linspace(0.0,pi,N+1)) # chebyshev points\n",
"fu = 0*xx\n",
"fc = 0*xx\n",
"for i in range(M):\n",
" fu[i] = omega(xx[i],xu)\n",
" fc[i] = omega(xx[i],xc)\n",
"plot(xx,fu,'b-',xx,fc,'r-')\n",
"legend((\"Uniform\",\"Chebyshev\"))\n",
"grid(True)\n",
"title(\"N = \"+str(N));"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}