Finding Inverse of a Matrix in R Programming - inv() Function Last Updated : 19 Jun, 2020 Comments Improve Suggest changes Like Article Like Report 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: Python3 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)) 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: Python3 1== # 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) 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 Comment More infoAdvertise with us Next Article Finding Inverse of a Matrix in R Programming - inv() Function N nidhi_biet Follow Improve Article Tags : R Language R Matrix-Function Similar Reads Get or Set Dimensions of a Matrix in R Programming - dim() Function The dim() function in R is used to get or set the dimensions of an object. This function is particularly useful when working with matrices, arrays, and data frames. Below, we will discuss how to use dim() to both retrieve and set dimensions, with examples for better understanding.Syntax: dim(x)Param 2 min read Convert an Object into a Matrix in R Programming - as.matrix() Function The as.matrix() function within R converts objects of various classes into a matrix. This can be helpful to work with structures of various data that can be converted into the matrix structure so that it becomes easier to analyze.Syntax: as.matrix(x)Parameters: x: Object to be convertedExample 1: Co 2 min read Getting the Determinant of the Matrix in R Programming - det() Function det() function in R Language is used to calculate the determinant of the specified matrix. Syntax: det(x, ...) Parameters: x: matrix Example 1: Python3 # R program to illustrate # det function # Initializing a matrix with # 3 rows and 3 columns x <- matrix(c(3, 2, 6, -1, 7, 3, 2, 6, -1), 3, 3) # 1 min read Getting a Matrix of number of columns in R Programming - col() Function col() function in R Language is used to get a matrix which contains the number of columns of the matrix passed to it as argument. Syntax: col(x, as.factor=FALSE) Parameters: x: matrix as.factor: a logical value indicating whether the value should be returned as a factor of column labels (created if 2 min read Construct a Diagonal Matrix in R Programming - diag() Function diag() function in R Language is used to construct a diagonal matrix. Syntax: diag(x, nrow, ncol)Parameters: x: value present as the diagonal elements. nrow, ncol: number of rows and columns in which elements are represented.  Example 1:  Python3 # R program to illustrate # diag function # Callin 1 min read Like