On the construction of matrix invariants with applications