matpow

0th

Percentile

Matrix Power

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

Keywords
arith, array
Usage
x %^% k
Arguments
x
a square matrix.
k
an integer, $k >= 0$.
Details

Argument $k$ is coerced to integer using as.integer.

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

Value

A matrix of the same dimension as x.

Note

If you think you need x^k for $k < 0$, then consider instead solve(x %^% (-k)).

See Also

%*% for matrix multiplication.

Aliases
  • %^%
  • matpow
Examples
A <- cbind(1, 2 * diag(3)[,-1])
A
A %^% 2
stopifnot(identical(A, A %^% 1),
          A %^% 2 == A %*% A)
Documentation reproduced from package DescTools, version 0.99.19, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.