{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# p22: 5'th eigenvector of Airy equation"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%config InlineBackend.figure_format='svg'\n",
"from chebPy import *\n",
"from numpy import dot,diag,real,argsort,zeros,linspace,polyval,polyfit,where\n",
"from scipy.linalg import eig\n",
"from scipy.special import airy\n",
"from matplotlib.pyplot import figure,subplot,plot,title"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/bf/9z7c3wfn7033kh93rp599rg00000gn/T/ipykernel_2210/1541387896.py:9: RankWarning: Polyfit may be poorly conditioned\n",
" xx = linspace(-1.0,1.0,200); vv = polyval(polyfit(x,v,N),xx);\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"figure(figsize=(10,8))\n",
"for N in range(12,60,12):\n",
" D,x = cheb(N); D2 = dot(D,D); D2 = D2[1:N,1:N]\n",
" Lam,V = eig(D2,diag(x[1:N]))\n",
" Lam = real(Lam); ii = where(Lam>0)[0]\n",
" V = real(V[:,ii]); Lam = Lam[ii]\n",
" ii = argsort(Lam); ii=ii[4]; Lam=Lam[ii]\n",
" v = zeros(N+1); v[1:N] = V[:,ii]; v = v/v[N//2]*airy(0.0)[0]\n",
" xx = linspace(-1.0,1.0,200); vv = polyval(polyfit(x,v,N),xx);\n",
" subplot(2,2,N//12); plot(xx,vv)\n",
" title(\"N = %d, eig = %15.10f\"%(N,Lam));"
]
}
],
"metadata": {
"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
}