问题
I am trying to compute Hamiltonian time evolution in sympy.
H is a matrix (Hamiltonian). For example : Matrix([[1, 2], [2, 2]]
t is a symbol : t=Symbol('t')
How can I easily compute A = exp (-i.H.t) ?
I try many things but without success : Calculation of eigenvalues, eigenvectors ...
回答1:
Should be able to do something like this:
import sympy
t = sympy.symbols('t')
H = sympy.Matrix([[1, 2], [2, 2]])
A = sympy.exp(-sympy.I * H * t) # sympy.I is imaginary constant
A
returns a complex sympy Matrix as expected.
回答2:
Is this what you want?
In [1]: M = Matrix([[1, 2], [2, 2]])
In [2]: (I*M*t).exp()
Out[2]:
⎡ 3⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t⎤
⎢ ───── + ─────── ───── + ─────── - ─────── + ───── - ─────── + ───── ───── + ─────── ───── + ─────── - ─────── + ───── - ─────── + ─────⎥
⎢ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ⎥
⎢ 4⋅√17⋅ℯ + 68⋅ℯ + 13⋅√17⋅ℯ + 85⋅ℯ 2⋅√17⋅ℯ + 18⋅ℯ - 18⋅ℯ - 2⋅√17⋅ℯ ⎥
⎢ ──────────────────────────────────────────────────────────────────────────────────────────────── ───────────────────────────────────────────────────────────────────────────────────────────────⎥
⎢ 17⋅√17 + 153 17 + 9⋅√17 ⎥
⎢ ⎥
⎢ ⎛ 3⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t⎞ 3⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t √17⋅ⅈ⋅t √17⋅ⅈ⋅t 3⋅ⅈ⋅t ⎥
⎢ ⎜ ───── + ─────── ───── + ─────── - ─────── + ───── - ─────── + ─────⎟ ───── + ─────── ───── + ─────── - ─────── + ───── ⎥
⎢ ⎜ 2 2 2 2 2 2 2 2 ⎟ 2 2 2 2 2 2 ⎥
⎢-⎝- 18⋅√17⋅ℯ - 34⋅ℯ + 34⋅ℯ + 18⋅√17⋅ℯ ⎠ √17⋅ℯ + 9⋅ℯ + 8⋅ℯ ⎥
⎢─────────────────────────────────────────────────────────────────────────────────────────────────────── ──────────────────────────────────────────────────────────────── ⎥
⎣ 17⋅√17 + 153 √17 + 17 ⎦
来源:https://stackoverflow.com/questions/61460662/sympy-exp-i-h-t