Mathematica: Anharmonic oscillator
Branislav K. Nikolić
Department of Physics & Astronomy, University of Delaware, Newark, DE 19716
EMAIL: bnikolic@udel.edu

1. Truncated Matrix Representations of Creation and Annihilation Operators

$Post=If[MatrixQ[#],MatrixForm[#],#]&  (*show matrices in human readable form*)

ac=Function[dim,Block[{i,j},Table[If[j==i-1,Sqrt[j],0],{i,1,dim},{j,1,dim}]]]; (*define matrix of creation operator of dimension dim*)

ac[8]

aa=Function[dim,ConjugateTranspose[ac[dim]]]; (*define matrix of annihilation operator of dimension dim*)

aa[8]

ac[8].aa[8](*number operator*)

aa[8].ac[8] (*Hermitian conjugate of number operator*)

aa[8].ac[8]-ac[8].aa[8] (*check commutation relation for bosonic operators*)

2. Exact Diagonalization of the Hamiltonian of Anharmonic Oscillator

trunc=8; (*dimension of truncated Hilbert space*)

lambda=0.1;(*strength of anharmonic λ*(X^4) term: H=H_harmonic + λ*(X^4)*)

HH=ac[trunc].aa[trunc]+(1/2)*IdentityMatrix[trunc] (*Hamiltonian of harmonic oscillator in second quantization*)

En=Eigenvalues[HH]//Sort (*find exact eigenenergies and sort them in ascending order*)

X=(ac[trunc]+aa[trunc])/Sqrt[2] (*coordinate operator in terms of annihilation and creation operators*)

HA=HH +lambda*(X.X.X.X) (*Hamiltonian of anharmonic oscillator in second quantization*)

EnExact=Eigenvalues[HA]//Sort(*find exact eigenenergies and sort them in ascending order*)

EnPerturbative=En+Table[(1/2)*lambda*(6*n^2+6*n+3),{n,0,trunc-1}] (*Eigenenergies corrected by first-order perturbation theory from PHYS814 quiz 1*)

100*Abs[(EnExact-EnPerturbative)/EnExact] (*relative error in % made by first-order perturbation theory*)

3. Divergent Perturbative Series in Quantum Mechanics

zex=Function[{g},Integrate[Exp[-x^2-g*x^4],{x,-Infinity,Infinity},Assumptions->g≥0]];

zser=Function[{g,n},Sum[(-g)^k/k!*Integrate[x^(4*k)*Exp[-x^2],{x,-Infinity,Infinity}],{k,0,n}]];

zex[1/50]

N[%,20]

N[zser[1/50,n=10],20]

Plot[zser[g=1/50,n],{n,0,50}]