I am trying to manipulate a Hamiltonian with non-commutative operators, $a_j,a_j^\dagger$. After some algebra using NCAlgebra package in Mathematica, I have an expression like, $$H = C_1 (b**a) + C_2 (a**a^\dagger) + C_3 (d^\dagger d) + \cdots $$
How do I extract/collect coefficients like $C_1,C_2$? I have tried NCCollect[H, b**a]
, but it does not give me the desired answer $C_1$?
I am new to this and appreciate any help. Thank you.
1 Answer
You can do this with NCCoefficientList
as in:
H = C1 b ** a + C2 a ** aj[a] + C3 d ** aj[d]
NCCoefficientList[H, {a, aj[a], b, d, aj[d]}]
which returns
{C1, C2, C3}
Note that you have to add also aj[a]
and aj[d]
to the list of variables.
NCCoefficientList[expr, {a, b}]
? $\endgroup$Coefficient[expr, SuperStar[b1] ** b2]
did the job. $\endgroup$