{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# p10: Polynomials and corresponding equipotential curves"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"%config InlineBackend.figure_format='svg'\n",
"from numpy import pi,linspace,arange,abs,cos,poly,polyval,meshgrid,real,imag\n",
"from matplotlib.pyplot import figure,subplot,plot,title,axis,contour"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"N = 16\n",
"figure(figsize=(9,8))\n",
"for i in range(2):\n",
" if i==0:\n",
" s = 'equispaced points'; x = -1.0 + 2.0*arange(0,N+1)/N\n",
" if i==1:\n",
" s = 'Chebyshev points'; x = -cos(pi*arange(0,N+1)/N)\n",
" p = poly(x)\n",
" # Plot p(x)\n",
" xx = linspace(-1.01,1.01,400,True)\n",
" pp = polyval(p,xx)\n",
" fig = subplot(2,2,2*i+1)\n",
" plot(x,0*x,'o',xx,pp)\n",
" fig.set_xlim(-1,1)\n",
" title(s)\n",
" \n",
" # Plot equipotential curves\n",
" subplot(2,2,2*i+2)\n",
" plot(real(x),imag(x),'o')\n",
" axis([-1.4,1.4,-1.12,1.12])\n",
" xgrid = linspace(-1.4,1.4,250,True)\n",
" ygrid = linspace(-1.12,1.12,250,True)\n",
" xx,yy = meshgrid(xgrid,ygrid,indexing='ij')\n",
" zz = xx + 1j*yy\n",
" pp = polyval(p,zz)\n",
" levels = 10.0**arange(-4,1)\n",
" contour(xx,yy,abs(pp),levels)\n",
" title(s);"
]
}
],
"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
}