Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


DescTools (version 0.99.43)

matpow: Matrix Power

Description

Compute the k-th power of a matrix. Whereas x^k computes element wise powers, x %^% k corresponds to k1 matrix multiplications, x %*% x %*% ... %*% x.

Usage

x %^% k

Arguments

x

a square matrix.

k

an integer, k0.

Value

A matrix of the same dimension as x.

Details

Argument k is coerced to integer using as.integer.

The algorithm uses O(log2(k)) matrix multiplications.

See Also

%*% for matrix multiplication.

Examples

Run this code
# NOT RUN {
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