qho_1d.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. from sympy.core import S, pi, Rational
  2. from sympy.functions import hermite, sqrt, exp, factorial, Abs
  3. from sympy.physics.quantum.constants import hbar
  4. def psi_n(n, x, m, omega):
  5. """
  6. Returns the wavefunction psi_{n} for the One-dimensional harmonic oscillator.
  7. Parameters
  8. ==========
  9. ``n`` :
  10. the "nodal" quantum number. Corresponds to the number of nodes in the
  11. wavefunction. ``n >= 0``
  12. ``x`` :
  13. x coordinate.
  14. ``m`` :
  15. Mass of the particle.
  16. ``omega`` :
  17. Angular frequency of the oscillator.
  18. Examples
  19. ========
  20. >>> from sympy.physics.qho_1d import psi_n
  21. >>> from sympy.abc import m, x, omega
  22. >>> psi_n(0, x, m, omega)
  23. (m*omega)**(1/4)*exp(-m*omega*x**2/(2*hbar))/(hbar**(1/4)*pi**(1/4))
  24. """
  25. # sympify arguments
  26. n, x, m, omega = map(S, [n, x, m, omega])
  27. nu = m * omega / hbar
  28. # normalization coefficient
  29. C = (nu/pi)**Rational(1, 4) * sqrt(1/(2**n*factorial(n)))
  30. return C * exp(-nu* x**2 /2) * hermite(n, sqrt(nu)*x)
  31. def E_n(n, omega):
  32. """
  33. Returns the Energy of the One-dimensional harmonic oscillator.
  34. Parameters
  35. ==========
  36. ``n`` :
  37. The "nodal" quantum number.
  38. ``omega`` :
  39. The harmonic oscillator angular frequency.
  40. Notes
  41. =====
  42. The unit of the returned value matches the unit of hw, since the energy is
  43. calculated as:
  44. E_n = hbar * omega*(n + 1/2)
  45. Examples
  46. ========
  47. >>> from sympy.physics.qho_1d import E_n
  48. >>> from sympy.abc import x, omega
  49. >>> E_n(x, omega)
  50. hbar*omega*(x + 1/2)
  51. """
  52. return hbar * omega * (n + S.Half)
  53. def coherent_state(n, alpha):
  54. """
  55. Returns <n|alpha> for the coherent states of 1D harmonic oscillator.
  56. See https://en.wikipedia.org/wiki/Coherent_states
  57. Parameters
  58. ==========
  59. ``n`` :
  60. The "nodal" quantum number.
  61. ``alpha`` :
  62. The eigen value of annihilation operator.
  63. """
  64. return exp(- Abs(alpha)**2/2)*(alpha**n)/sqrt(factorial(n))