{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# p11: Chebyshev differentiation of a smooth function\n",
"\n",
"$$\n",
"u(x) = e^x \\sin(5x), \\qquad x \\in [-1,1]\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%config InlineBackend.figure_format='svg'\n",
"from numpy import linspace,exp,sin,dot\n",
"from matplotlib.pyplot import figure,subplot,plot,title\n",
"from chebPy import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"xx = linspace(-1.0,1.0,200,True)\n",
"uu = exp(xx)*sin(5.0*xx)\n",
"c = 1; figure(figsize=(10,8))\n",
"for N in [10,20]:\n",
" D,x = cheb(N); u = exp(x)*sin(5.0*x)\n",
" subplot(2,2,c); c += 1\n",
" plot(x,u,'o',xx,uu)\n",
" title('u(x), N='+str(N))\n",
" \n",
" error = dot(D,u) - exp(x)*(sin(5.0*x)+5.0*cos(5.0*x))\n",
" subplot(2,2,c); c += 1\n",
" plot(x,error,'o-')\n",
" title('error in u\\'(x), N='+str(N));"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}