A <- cbind(1, 2 * diag(3)[,-1])
A
A %^% 2
stopifnot(identical(A, A %^% 1),
A %^% 2 == A %*% A)
## also for complex number matrix Z :
Z <- A + 2i*A
Z %^% 2
stopifnot(identical(Z, Z %^% 1),
Z %^% 2 == Z %*% Z)
Run the code above in your browser using DataLab