Commutator
C = commutator(X, Y)
C = commutator(X, Y) returns X * Y - Y * X. The parameters may be quaternions, octonions, or anything else that makes sense. The multiplication used is matrix multiplication. No check is made on whether the parameters are of compatible types.
Reals commute so the commutator of any two reals will be zero:
>> commutator(randn, randn) ans = 0
Matrix multiplication is not commutative, so two chosen at random will have a non-zero commutator:
>> commutator(randn(2), randn(2)) ans = 0.5833 0.7793 -1.1566 -0.5833
Quaternions and octonions do not commute so any two of each will have a non-zero commutator:
>> commutator(randq, randq) ans = -0.5486 * I + 0.2534 * J + 1.057 * K >> commutator(rando, rando) ans = -0.1776 * I - 0.2875 * J + 0.6161 * K - 0.6575 * L - 0.3949 * M - 1.221 * N + 0.4269 * O