Using the Cayley-Hamilton theorem with N-partitioned matrices