You are here: Home / Exercises / 2014 / isacker / hon.m

hon.m

Objective-C source code icon hon.m — Objective-C source code, 1 KB

File contents

(* ::Package:: *)

(*** Harmonic oscillator matrix elements ***)
(* Ndiv lists all non-negative integer partitions of N=i1+i2+...+in *)
Ndiv[1,N_]:={{N}};
Ndiv[n_,0]:={Table[0,{i,1,n}]};
Ndiv[n_,N_]:=Flatten[Table[Map[(Join[#,{i}])&,Ndiv[n-1,N-i]],{i,0,N}],1];

(* Matrix elements of bi+ bj in the shell N of the HO in n dimensions *)
(* State: {i1,i2,...,in};
   Creation operator: {0,...,1,...0}
   Annihilation operator: {0,...,-1,...,0} *)
me[n_,N_,bd_,b_,bra_,ket_]:=Sqrt[-(bd.bra)*(b.ket)]*If[ket+b==bra-bd,1,0];
mat[n_,N_,bd_,b_]:=
(bas=Ndiv[n,N];k=Length[bas];
 Table[me[n,N,bd,b,bas[[bra]],bas[[ket]]],{ket,1,k},{bra,1,k}]);
Lx[N_]:=-I*mat[3,N,{0,1,0},{0,0,-1}]+I*mat[3,N,{0,0,1},{0,-1,0}];
Ly[N_]:=-I*mat[3,N,{0,0,1},{-1,0,0}]+I*mat[3,N,{1,0,0},{0,0,-1}];
Lz[N_]:=-I*mat[3,N,{1,0,0},{0,-1,0}]+I*mat[3,N,{0,1,0},{-1,0,0}];