powered by
x^k
x %^% k
x %*% x %*% ... %*% x
matrix
x
as.integer
The algorithm uses $O(log2(k))$ matrix multiplications.
%*%
A <- cbind(1, 2 * diag(3)[,-1]) A A %^% 2 stopifnot(identical(A, A %^% 1), A %^% 2 == A %*% A)
Run the code above in your browser using DataLab