'How to factor powers of an matrix in a equation in Sympy?
I have an expression that comes from
from sympy.physics.quantum import Commutator as cmm
x, t, A, V, W, D = sp.symbols('x t A V W D', commutative = False)
Q = sp.Function('Q', commutative = False)
F = (sp.diff(Q(x,t),x)+ cmm(W,Q(x,t)).doit() - sp.I*cmm(A,Q(x,t)+ cmm(W,Q(x,t)).doit()).doit())*(sp.diff(Q(x,t),x)+ cmm(W,Q(x,t)).doit() - sp.I*cmm(A,Q(x,t)+ cmm(W,Q(x,t)).doit()).doit())
F.expand()
This gives me an expression with elements with zero order in W, with first order in W and second order. I want to get only the first order W's. I tried the factorization procedures but it appears that, due to the fact of no commutation, it doesn't recognize powers of W. It always gives me 0. Is there any simple way of doing this ? Of course I can do it by hand but this is not my goal.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|