Harmonic oscillator

A harmonic oscillator is a particle in a potential energy well given by
V(x)=
1
2
kx², where k is the a positive constant (elastic constant).
In[]:=
ClearAll["Global`*"]​​​​(*Thedimensionsoftheimagesproducedareset:400isthewidthand200istheheight.*)​​MyImageSize={400,200};​​
In[]:=
​​​​$Assumptions=​​x∈Reals&&(*VariablePositiononthexaxis*)​​p∈Reals&&(*VariableMomentum*)​​ℏ∈Reals&&ℏ>0&&(*Planckconstant*)​​m∈Reals&&m>0&&(*Massoftheparticle*)​​n∈Integers&&n>0&&(*Integerfornumberofsolutions*)​​k∈Reals&&k>0&&(*Elasticconstantofthespring*)​​ω∈Reals&&ω>0(*Pulsationrate*);

SolutionsoftheSchröedingerequation:
φ
1
(x),
φ
2
(x),
φ
3
(x)

In this notebook, for simplicity, we do not solve the Schröedinger equation but we immediately write the solutions and show that they satisfy the Schröedinger equation .
The Schröedinger equation is solvable only for the discrete values of the Energy En[n], they are all possible values for energy. Each solution φ (n, x) represents a physical state and it is associated with its respective energy En[n] .
We define the angular frequency:
In[]:=
ω=
k
m
;
The energy levels numbered with n=0,1,2,3..
In[]:=
En[n_]:=ℏωn+
1
2
;
Each solution φ (n, x) represents a physical state and it is associated with its respective energy En[n] .
In[]:=
φ[n_,x_]:=
1
n
2
n!
1
4
mω
πℏ
-
mω
2
x
2ℏ

HermiteHn,
mω
ℏ
x
Solution for n = 1
In[]:=
φ[1,x]//Simplify
Out[]=
2
-
km
2
x
2ℏ

3/8
(km)
x
1/4
π
3/4
ℏ
Solution for n = 2
In[]:=
φ[2,x]//Simplify
Out[]=
-
km
2
x
2ℏ

1/8
(km)
2
km
2
x
-ℏ
2
1/4
π
5/4
ℏ
Solution for n = 3
In[]:=
φ[3,x]//Simplify
Out[]=
-
km
2
x
2ℏ

3/8
(km)
x2
km
2
x
-3ℏ
3
1/4
π
7/4
ℏ
The elastic potential V (x) written as a function of angular frequency ω:
In[]:=
V[x_]:=
1
2
m
2
ω
2
x
;
The
φ
n
(x)satisfytheSchroedingerequationforeachvalueofn,trytochangethevalueofn=0,1,2,3,...
In[]:=
n=1;​​-
2
ℏ
2m
∂
x
∂
x
φ[n,x]+V[x]φ[n,x]==En[n]φ[n,x]//FullSimplify
Out[]=
True
The
φ
n
(x)arenormalizedforeachvalueofn,trytochangethevalueofn=0,1,2,3,...
In[]:=
n=1;​​
∞
∫
-∞
2
Abs[φ[0,x]]
x1
Out[]=
True
Mean value of x is zero for each value of n, try to change the value of n = 0, 1, 2, 3, ...
In[]:=
n=1;​​
x
=
+∞
∫
-∞
x
2
Abs[φ[n,x]]
x
Out[]=
0
In order to create the graphs, let' s fix the value of the following three constants
In[]:=
ℏ=1;​​m=1;​​k=0.1;
Wedefinethefollowingfunctiontodrawthegraphsofrealfunction
φ
n
(x)
In[]:=
MainColorPlot=ColorData[97,"ColorList"][[1]];​​​​GeneratePlot1[En_,f_,fLabel_]:=Plot[​​{2f,V[x]-En},​​{x,-9,9},​​PlotRange{-1.5,1.5},​​PlotStyle->{Default,Orange},​​Filling{2->Bottom},​​Ticks{None,None},​​AxesStyleDirective[Thickness[0.003],Arrowheads[{0.04}]],​​AxesLabel{"x",Style[fLabel,MainColorPlot]},​​PlotPoints100,​​Epilog{Text[Style["U(x)",Red],{-7.5,1.2}]},​​BaseStyle12,​​ImageSizeMyImageSize,​​AspectRatioFull];
Note that the potential has several different heights for each graph because each value of n corresponds to a different value of the energy En[n]
In[]:=
GeneratePlot1[En[0],φ[0,x],"
φ
0
​(x)"]​​GeneratePlot1[En[1],φ[1,x],"
φ
1
​(x)"]​​GeneratePlot1[En[2],φ[2,x],"
φ
2
​(x)"]​​
Out[]=
Out[]=
Out[]=
In[]:=
​
Note that the potential has several different heights for each graph because each value of n corresponds to a different value of the energy En[n]
The ProbP functions are the probability density of the momentum p, for any given n=0,1,2.
As in the case of the classical particle, the mean value of p is zero