Dynamics of the
Harmonic Oscillator

Definition

Needs["Graphics`MultipleListPlot`"];
c[x0_, σ_, n_, Nt_, flag_] :=Block[{T  =  4 π ,  dt  =  2  π/Nt},
					If[flag  == 1, 
(* Gaussian wavefunction *)              cc =  
                        Table[NIntegrate[(E^(-((((x - x0))^2)/(2 (σ^2))))) (E^(-((x^2)/2))) 
                                HermiteH[i, 
                                  x], {x, -∞, ∞}]/((2^i)  i! (Sqrt[π])), {i, 0, n}];,
        cc  =  
                        Table[NIntegrate[(E^(-((x^2)/2))) HermiteH[i, x], {x, x0 - σ, 
                                  x0 + σ}]/((2^i)  i! (Sqrt[π])), {i, 0, n}]/Sqrt[3. ];
						];
					Table[{
							dd        = 
                          Table[cc[[i]] (E^(- I (i + 1/2) t)), {i, 1, n + 1}];
							f[x_] =  
                          Sum[ dd[[i]]  HermiteH[i - 1, x], {i, 1, 
                                n + 1}] * (E^(-(x^2)/2));
							xx        =  
                          Table[x, {x, -10, 10,  .1}];
							v           =  
                          Map[f, xx];
							tp         =  
                          Transpose[{xx, Abs[v]^2}];
							ti         =  
                          Transpose[{xx, Re[v]}];
							  
							\(MultipleListPlot[{tp, ti}, 
                          PlotJoined -> 
                            True, 
								SymbolShape -> 
                            None, 
								PlotStyle -> {{Thickness[ .005], Hue[0.6]}, {Thickness[ .005], 
                                Hue[1.0]}}, 
								PlotRange -> {{\(-x0\) - \ 3  σ\ , 
                                x0 + 3  σ}, {\(-1\), \ 1}}]\)
							},{t, 0, T, dt}];
					SelectionMove[EvaluationNotebook[], After, 
                  EvaluationCell];
					SelectionMove[EvaluationNotebook[], Next, 
                  CellGroup];
					FrontEndTokenExecute["OpenCloseGroup"]
						];

Gauß-Paket

c[x0 = 5, σ =  .5, n = 30, Nt = 40, flag = 1]

Kastenförmiges Wellenpaket

c[x0 = 5, σ = 2, n = 50, Nt = 40, flag = 2]