A real quaternion matrix equation with applications