Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. (* Source code written in Mathematica 6.0 by Steve Byrnes, Feb. 2011. This source code is public domain. *)
  2. (* Shows classical and quantum trajectory animations for a harmonic potential. Assume m=w=hbar=1. *)
  3. ClearAll["Global`*"]
  4. (*** Wavefunctions of the energy eigenstates ***)
  5. psi[n_, x_] := (2^n*n!)^(-1/2)*Pi^(-1/4)*Exp[-x^2/2]*HermiteH[n, x];
  6. energy[n_] := n + 1/2;
  7. psit[n_, x_, t_] := psi[n, x] Exp[-I*energy[n]*t];
  8. (*** A random time-dependent state ***)
  9. SeedRandom[1];
  10. CoefList = Table[Random[]*Exp[2 Pi I Random[]], {n, 0, 4}];
  11. CoefList = CoefList/Norm[CoefList];
  12. Randpsi[x_, t_] := Sum[CoefList[[n + 1]]*psit[n, x, t], {n, 0, 4}];
  13. (*** A coherent state (or "Glauber state") ***)
  14. CoherentState[b_, x_, t_] := Exp[-Abs[b]^2/2] Sum[b^n*(n!)^(-1/2)*psit[n, x, t], {n, 0, 15}];
  15. (*** Make the classical plots...a red ball anchored to the origin by a gray spring. ***)
  16. classical1[t_, max_] := ListPlot[{{max Cos[t], 0}}, PlotStyle -> Directive[Red, AbsolutePointSize[15]]];
  17. zigzag[x_] := Abs[(x + 0.25) - Round[x + 0.25]] - .25;
  18. spring[x_, left_, right_] := (.9 zigzag[3 (x - left)/(right - left)])/(1 + Abs[right - left]);
  19. classical2[t_, max_] := Plot[spring[x, -5, max Cos[t]], {x, -5, max Cos[t]}, PlotStyle -> Directive[Gray, Thick]];
  20. classical3 = ListPlot[{{-5, 0}}, PlotStyle -> Directive[Black, AbsolutePointSize[7]]];
  21. classical[t_, max_, label_] := Show[classical2[t, max], classical1[t, max], classical3,
  22. PlotRange -> {{-5, 5}, {-1, 1}}, Ticks -> None, Axes -> {False, True}, PlotLabel -> label, AxesOrigin -> {0, 0}];
  23. (*** Put all the plots together ***)
  24. SetOptions[Plot, {PlotRange -> {-1, 1}, Ticks -> None, PlotStyle -> {Directive[Thick, Blue], Directive[Thick, Pink]}}];
  25. MakeFrame[t_] := GraphicsGrid[
  26. {{classical[t + 2, 1.5, "A"], classical[t, 3, "B"]},
  27. {Plot[{Re[psit[0, x, t]], Im[psit[0, x, t]]}, {x, -5, 5}, PlotLabel -> "C"],
  28. Plot[{Re[psit[1, x, t]], Im[psit[1, x, t]]}, {x, -5, 5}, PlotLabel -> "D"]},
  29. {Plot[{Re[psit[2, x, t]], Im[psit[2, x, t]]}, {x, -5, 5}, PlotLabel -> "E"],
  30. Plot[{Re[psit[3, x, t]], Im[psit[3, x, t]]}, {x, -5, 5}, PlotLabel -> "F"]},
  31. {Plot[{Re[Randpsi[x, t]], Im[Randpsi[x, t]]}, {x, -5, 5}, PlotLabel -> "G"],
  32. Plot[{Re[CoherentState[1, x, t]], Im[CoherentState[1, x, t]]}, {x, -5, 5}, PlotLabel -> "H"]}
  33. }, Frame -> All, ImageSize -> 300];
  34. output = Table[MakeFrame[t], {t, 0, 4 Pi*96/97, 4 Pi/97}];
  35. SetDirectory["C:\Users\Steve\Desktop"]
  36. Export["test.gif", output]
  37.  
  38. psit[n_, x_, t_] := psi[n, x] Exp[-I*energy[n]*t];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement