Lets take a third power as example.
A^3 = A*A*A = [n x m]*[n x m]*[n x m]
To be compatible, adjacent sizes must be equal
Therefore, for this operation to be valid, n and m must be equal
If instead you meant element-wise operations, you should replace all matrix operation with the other version. That means replacing every * with .* and every ^ with .^ (plus and minus will always work element-wise).
I hope this formula was generated procedurally and not written by hand, because that would be a nightmare to debug. Especially with all those numbered variables, instead of arrays.