{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# p24: Pseudospectra of Davies's complex harmonic oscillator"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"%config InlineBackend.figure_format = 'svg'\n",
"from chebPy import cheb\n",
"from numpy import dot,argsort,zeros,real,imag,meshgrid,eye,diag,arange\n",
"from scipy.linalg import solve,eig,svd,svdvals\n",
"from matplotlib.pyplot import figure,plot,title,axis,contour"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"N = 70; D, x = cheb(N); x = x[1:N];\n",
"L = 6.0; x = L*x; D = D/L;\n",
"A = -dot(D,D);\n",
"A = A[1:N,1:N] + (1+3j)*diag(x**2);\n",
"lam, v = eig(A)\n",
"fig = figure()\n",
"plot(real(lam),imag(lam),\"o\")\n",
"axis([0, 50, 0, 40])\n",
"\n",
"h = 0.5 # Smaller the value, finer the plot\n",
"x = arange(0,50+h,h); y = arange(0,40+h,h); xx,yy = meshgrid(x,y,indexing='ij');\n",
"zz = xx + 1j*yy;\n",
"I = eye(N-1); sigmin = zeros((len(x),len(y))) \n",
"for i in range(0,len(x)):\n",
" for j in range(0,len(y)):\n",
" sigmin[i,j] = min(svdvals(zz[i,j]*I - A));\n",
"\n",
"levels = 10.0**arange(-4.5,0.0,0.5);\n",
"contour(xx,yy,sigmin,levels,colors = 'k');"
]
}
],
"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
}