{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Chebyshev polynomials"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'svg'\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"def chebyshev(n, x):\n",
" if n == 0:\n",
" y = np.ones(len(x))\n",
" elif n == 1:\n",
" y = x.copy()\n",
" else:\n",
" y = 2*x*chebyshev(n-1,x) - chebyshev(n-2,x)\n",
" return y"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"N = 200\n",
"x = np.linspace(-1.0,1.0,N)\n",
"plt.figure(figsize=(8,6))\n",
"for n in range(0,6):\n",
" y = chebyshev(n,x)\n",
" plt.plot(x,y)\n",
"plt.grid(True)\n",
"plt.xlabel('x')\n",
"plt.ylabel('$T_n(x)$');"
]
}
],
"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": 2
}