Skip to contents

inv_p() finds the inverse of a square matrix over the field \(F_p\). The function checks for invertibility and then row-reduces the augmented matrix \([A|I]\) over \(F_p\) to find the inverse.

Usage

inv_p(A, p)

Arguments

A

A square matrix

p

A prime integer

Value

A square matrix of the same size as A

Examples

B <- matrix(c(5, 2, 3, 6, 5, 5, 4, 0, 2), 3, 3)
inv_p(B, 7)
#>      [,1] [,2] [,3]
#> [1,]    4    6    6
#> [2,]    4    2    6
#> [3,]    5    0    1
C <- matrix(c(3, 0, 4, 0, 2, 1, 1, 3, 0, 3, 0, 1, 3, 0, 2, 1), 4, 4)
inv_p(C, 5)
#>      [,1] [,2] [,3] [,4]
#> [1,]    4    3    1    1
#> [2,]    1    3    3    1
#> [3,]    3    1    4    3
#> [4,]    4    0    2    0