图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB

  1. from sympy.core import Basic
  2. from sympy.functions import adjoint, conjugate
  3. from sympy.matrices.expressions.transpose import transpose
  4. from sympy.matrices.expressions.matexpr import MatrixExpr
  5. class Adjoint(MatrixExpr):
  6. """
  7. The Hermitian adjoint of a matrix expression.
  8. This is a symbolic object that simply stores its argument without
  9. evaluating it. To actually compute the adjoint, use the ``adjoint()``
  10. function.
  11. Examples
  12. ========
  13. >>> from sympy import MatrixSymbol, Adjoint, adjoint
  14. >>> A = MatrixSymbol('A', 3, 5)
  15. >>> B = MatrixSymbol('B', 5, 3)
  16. >>> Adjoint(A*B)
  17. Adjoint(A*B)
  18. >>> adjoint(A*B)
  19. Adjoint(B)*Adjoint(A)
  20. >>> adjoint(A*B) == Adjoint(A*B)
  21. False
  22. >>> adjoint(A*B) == Adjoint(A*B).doit()
  23. True
  24. """
  25. is_Adjoint = True
  26. def doit(self, **hints):
  27. arg = self.arg
  28. if hints.get('deep', True) and isinstance(arg, Basic):
  29. return adjoint(arg.doit(**hints))
  30. else:
  31. return adjoint(self.arg)
  32. @property
  33. def arg(self):
  34. return self.args[0]
  35. @property
  36. def shape(self):
  37. return self.arg.shape[::-1]
  38. def _entry(self, i, j, **kwargs):
  39. return conjugate(self.arg._entry(j, i, **kwargs))
  40. def _eval_adjoint(self):
  41. return self.arg
  42. def _eval_conjugate(self):
  43. return transpose(self.arg)
  44. def _eval_trace(self):
  45. from sympy.matrices.expressions.trace import Trace
  46. return conjugate(Trace(self.arg))
  47. def _eval_transpose(self):
  48. return conjugate(self.arg)