Matrix equations and trilinear commutation relations