Raise a matrix to a fractional power in R
Matrices can be raised to integral as well as non-integral powers in R Programming Language. The computation of power of a matrix involves simultaneous multiplication of matrix as many times as the power integer is specified. However, in the case of fractional powers, we need to use the in-built R functions to simulate this operation.
Method 1: Using expm package in R
The expm package can be used to perform various types of matrix computations, like logarithm, exponential, and others. This function computes the exponential of a square matrix, which is non-diagonalizable. The expm package includes logm and sqrtm methods, respectively. However, it cannot be used to work with negative fractional powers. The expm package can be installed in R directory using the following command :
The package is included in the script and then the expm method can be used which has the following syntax :
expm(x), where x is the matrix
 "Original Matrix" [,1] [,2] [1,] 1 1 [2,] 1 1  "Power Matrix" [,1] [,2] [1,] 1.071773 1.071773 [2,] 1.071773 1.071773
Method 2: Using powerplus package in R
Matrices can be raised to negative or positive non-integral powers using the powerplus package in R. It is used to raise a valid matrix to any power (even complex numbers are allowed). The matrices that can be used are either square matrices or diagonalisable matrices with positive eigenvalues. The powerplus package can be installed into the R directory by using the following command :
The package can then be included in the script and then the Matpow() method can be used, which can be used to exponential power computation of a square matrix.
Syntax: Matpow(M, power_number)
- M – A diagnosable square matrix
- power_number – The non-integral power factor of the matrix
Returns : A matrix raised to the power_number factor.
Example 1: The following examples illustrate the Matpow() method in R.
 "Original Matrix" [,1] [,2] [1,] 1 1 [2,] 0 1  "Power Matrix" [,1] [,2] [1,] 1 0.5 [2,] 0 1.0
Example 2: Negative integral powers.
Matpow() methods can be used to work out with negative integral powers also. The output is the negative matrix in case the result is odd, otherwise even.
 "Original Matrix" [,1] [,2] [1,] 2 1 [2,] 0 1  "Power Matrix" [,1] [,2] [1,] 0.2332582 -0.7667418 [2,] 0.0000000 1.0000000