Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

inv

Matrix Inverse (Matlab Style)


Description

Invert a numeric or complex matrix.

Usage

inv(a)

Arguments

a

real or complex square matrix

Details

Computes the matrix inverse by calling solve(a) and catching the error if the matrix is nearly singular.

Value

square matrix that is the inverse of a.

Note

inv() is the function name used in Matlab/Octave.

See Also

Examples

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

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.