inv | R Documentation |
Invert a numeric or complex matrix.
inv(a)
a |
real or complex square matrix |
Computes the matrix inverse by calling solve(a)
and catching the error
if the matrix is nearly singular.
square matrix that is the inverse of a
.
inv()
is the function name used in Matlab/Octave.
solve
A <- hilb(6)
B <- inv(A)
B
# Compute the inverse matrix through Cramer's rule:
n <- nrow(A)
detA <- det(A)
b <- matrix(NA, nrow = n, ncol = n)
for (i in 1:n) {
for (j in 1:n) {
b[i, j] <- (-1)^(i+j) * det(A[-j, -i]) / detA
}
}
b
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.