piab.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """1D quantum particle in a box."""
  2. from sympy.core.numbers import pi
  3. from sympy.core.singleton import S
  4. from sympy.core.symbol import Symbol
  5. from sympy.functions.elementary.miscellaneous import sqrt
  6. from sympy.functions.elementary.trigonometric import sin
  7. from sympy.sets.sets import Interval
  8. from sympy.physics.quantum.operator import HermitianOperator
  9. from sympy.physics.quantum.state import Ket, Bra
  10. from sympy.physics.quantum.constants import hbar
  11. from sympy.functions.special.tensor_functions import KroneckerDelta
  12. from sympy.physics.quantum.hilbert import L2
  13. m = Symbol('m')
  14. L = Symbol('L')
  15. __all__ = [
  16. 'PIABHamiltonian',
  17. 'PIABKet',
  18. 'PIABBra'
  19. ]
  20. class PIABHamiltonian(HermitianOperator):
  21. """Particle in a box Hamiltonian operator."""
  22. @classmethod
  23. def _eval_hilbert_space(cls, label):
  24. return L2(Interval(S.NegativeInfinity, S.Infinity))
  25. def _apply_operator_PIABKet(self, ket, **options):
  26. n = ket.label[0]
  27. return (n**2*pi**2*hbar**2)/(2*m*L**2)*ket
  28. class PIABKet(Ket):
  29. """Particle in a box eigenket."""
  30. @classmethod
  31. def _eval_hilbert_space(cls, args):
  32. return L2(Interval(S.NegativeInfinity, S.Infinity))
  33. @classmethod
  34. def dual_class(self):
  35. return PIABBra
  36. def _represent_default_basis(self, **options):
  37. return self._represent_XOp(None, **options)
  38. def _represent_XOp(self, basis, **options):
  39. x = Symbol('x')
  40. n = Symbol('n')
  41. subs_info = options.get('subs', {})
  42. return sqrt(2/L)*sin(n*pi*x/L).subs(subs_info)
  43. def _eval_innerproduct_PIABBra(self, bra):
  44. return KroneckerDelta(bra.label[0], self.label[0])
  45. class PIABBra(Bra):
  46. """Particle in a box eigenbra."""
  47. @classmethod
  48. def _eval_hilbert_space(cls, label):
  49. return L2(Interval(S.NegativeInfinity, S.Infinity))
  50. @classmethod
  51. def dual_class(self):
  52. return PIABKet