mpower: General Matrix Power

View source: R/mpower.R

mpowerR Documentation

General Matrix Power

Description

Calculates the n-th power of a square matrix, where n can be a positive or negative integer or a fractional power.

Usage

mpower(A, n)

A %^% n

Arguments

A

A square matrix. Must also be symmetric for non-integer powers.

n

matrix power

Details

If n<0, the method is applied to A^{-1}. When n is an integer, the function uses the Russian peasant method, or repeated squaring for efficiency. Otherwise, it uses the spectral decomposition of A, \mathbf{A}^n = \mathbf{V} \mathbf{D}^n \mathbf{V}^{T} requiring a symmetric matrix.

Value

Returns the matrix A^n

Author(s)

Michael Friendly

References

https://en.wikipedia.org/wiki/Exponentiation_by_squaring

See Also

Packages corpcor and expm define similar functions.

Examples


M <- matrix(sample(1:9), 3,3)
mpower(M,2)
mpower(M,4)

# make a symmetric matrix
MM <- crossprod(M)
mpower(MM, -1)
Mhalf <- mpower(MM, 1/2)
all.equal(MM, Mhalf %*% Mhalf)



mvinfluence documentation built on Sept. 21, 2022, 9:09 a.m.