inv() function in R Language is used to calculate inverse of a matrix.
Note: Determinant of the matrix must not be zero
Syntax: inv(x)
Parameters:
x: Matrix
Example 1:
# R program to calculate # inverse of a matrix # Loading library library(matlib) # Create 3 different vectors. a1 <- c(3, 2, 8) a2 <- c(6, 3, 2) a3 <- c(5, 2, 4) # Bind the 3 matrices row-wise # using the rbind() function. A <- rbind(a1, a2, a3) # find inverse using the inv() function. print(inv(A)) |
chevron_right
filter_none
Output:
[, 1] [, 2] [, 3]
[1, ] -0.2857143 -0.2857143 0.7142857
[2, ] 0.5000000 1.0000000 -1.5000000
[3, ] 0.1071429 -0.1428571 0.1071429
Example 2:
# R program to calculate # inverse of a matrix # Loading Library library(matlib) # Creating a matrix A = matrix(c(2, 5, 3, 4, 5, 2, 6, 3, 4), 3, 3) det(A) # Calling inv() function cat("Inverse of A:\n") inv(A) |
chevron_right
filter_none
Output:
[1] -46
Inverse of A:
[, 1] [, 2] [, 3]
[1, ] -0.3043478 0.08695652 0.3913044
[2, ] 0.2391304 0.21739130 -0.5217391
[3, ] 0.1086957 -0.17391304 0.2173913
Recommended Posts:
- Calculate Inverse sine of a value in R Programming - asin() Function
- Calculate Inverse cosine of a value in R Programming - acos() Function
- Calculate Inverse tangent of a value in R Programming - atan() Function
- Perform the Inverse Probability Cumulative Density Analysis on t-Distribution in R Programming - qt() Function
- Inverse of Matrix in R
- Check if the Object is a Matrix in R Programming - is.matrix() Function
- Convert a Data Frame into a Numeric Matrix in R Programming - data.matrix() Function
- Convert an Object into a Matrix in R Programming - as.matrix() Function
- Finding the length of string in R programming - nchar() method
- Transform the Scaled Matrix to its Original Form in R Programming - Using Matrix Computations
- Finding Day and Month on a Specific Date in R Language - weekday() and month() function
- Getting the Modulus of the Determinant of a Matrix in R Programming - determinant() Function
- Return a Matrix with Lower Triangle as TRUE values in R Programming - lower.tri() Function
- Compute Choleski factorization of a Matrix in R Programming - chol() Function
- Get or Set Dimensions of a Matrix in R Programming - dim() Function
- Calculate the Sum of Matrix or Array columns in R Programming - colSums() Function
- Getting a Matrix of number of columns in R Programming - col() Function
- Calculate the Mean of each Column of a Matrix or Array in R Programming - colMeans() Function
- Calculate the cross-product of a Matrix in R Programming - crossprod() Function
- Calculate the cross-product of the Transpose of a Matrix in R Programming - tcrossprod() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

