Uses gaussianElimination
to find the inverse of a square, non-singular matrix, \(X\).
Inverse(X, tol = sqrt(.Machine$double.eps), ...)
a square numeric matrix
tolerance for checking for 0 pivot
other arguments passed on
the inverse of X
The method is purely didactic: The identity matrix, \(I\), is appended to \(X\), giving \(X | I\). Applying Gaussian elimination gives \(I | X^{-1}\), and the portion corresponding to \(X^{-1}\) is returned.
A <- matrix(c(2, 1, -1,
-3, -1, 2,
-2, 1, 2), 3, 3, byrow=TRUE)
Inverse(A)
#> [,1] [,2] [,3]
#> [1,] 4 3 -1
#> [2,] -2 -2 1
#> [3,] 5 4 -1
Inverse(A, verbose=TRUE, fractions=TRUE)
#>
#> Initial matrix:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 2 1 -1 1 0 0
#> [2,] -3 -1 2 0 1 0
#> [3,] -2 1 2 0 0 1
#>
#> row: 1
#>
#> exchange rows 1 and 2
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -3 -1 2 0 1 0
#> [2,] 2 1 -1 1 0 0
#> [3,] -2 1 2 0 0 1
#>
#> multiply row 1 by -1/3
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 1/3 -2/3 0 -1/3 0
#> [2,] 2 1 -1 1 0 0
#> [3,] -2 1 2 0 0 1
#>
#> multiply row 1 by 2 and subtract from row 2
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 1/3 -2/3 0 -1/3 0
#> [2,] 0 1/3 1/3 1 2/3 0
#> [3,] -2 1 2 0 0 1
#>
#> multiply row 1 by 2 and add to row 3
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 1/3 -2/3 0 -1/3 0
#> [2,] 0 1/3 1/3 1 2/3 0
#> [3,] 0 5/3 2/3 0 -2/3 1
#>
#> row: 2
#>
#> exchange rows 2 and 3
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 1/3 -2/3 0 -1/3 0
#> [2,] 0 5/3 2/3 0 -2/3 1
#> [3,] 0 1/3 1/3 1 2/3 0
#>
#> multiply row 2 by 3/5
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 1/3 -2/3 0 -1/3 0
#> [2,] 0 1 2/5 0 -2/5 3/5
#> [3,] 0 1/3 1/3 1 2/3 0
#>
#> multiply row 2 by 1/3 and subtract from row 1
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 0 -4/5 0 -1/5 -1/5
#> [2,] 0 1 2/5 0 -2/5 3/5
#> [3,] 0 1/3 1/3 1 2/3 0
#>
#> multiply row 2 by 1/3 and subtract from row 3
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 0 -4/5 0 -1/5 -1/5
#> [2,] 0 1 2/5 0 -2/5 3/5
#> [3,] 0 0 1/5 1 4/5 -1/5
#>
#> row: 3
#>
#> multiply row 3 by 5
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 0 -4/5 0 -1/5 -1/5
#> [2,] 0 1 2/5 0 -2/5 3/5
#> [3,] 0 0 1 5 4 -1
#>
#> multiply row 3 by 4/5 and add to row 1
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 0 0 4 3 -1
#> [2,] 0 1 2/5 0 -2/5 3/5
#> [3,] 0 0 1 5 4 -1
#>
#> multiply row 3 by 2/5 and subtract from row 2
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 0 0 4 3 -1
#> [2,] 0 1 0 -2 -2 1
#> [3,] 0 0 1 5 4 -1
#> [,1] [,2] [,3]
#> [1,] 4 3 -1
#> [2,] -2 -2 1
#> [3,] 5 4 -1