Open In App
Related Articles

Getting the Determinant of the Matrix in R Programming – det() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

det() function in R Language is used to calculate the determinant of the specified matrix.

Syntax: det(x, …)

Parameters:
x: matrix

Example 1:




# 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)
  
# Getting the matrix representation
x
  
# Calling the det() function
det(x)


Output:

     [, 1] [, 2] [, 3]
[1, ]    3   -1    2
[2, ]    2    7    6
[3, ]    6    3   -1

[1] -185

Example 2:




# 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)
  
# Getting the matrix representation
x
  
# Getting the transpose of the matrix x
y <- t(x)
y
  
# Calling the det() function
det(y)


Output:

     [, 1] [, 2] [, 3]
[1, ]    3   -1    2
[2, ]    2    7    6
[3, ]    6    3   -1

     [, 1] [, 2] [, 3]
[1, ]    3    2    6
[2, ]   -1    7    3
[3, ]    2    6   -1

[1] -185

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 03 Jun, 2020
Like Article
Save Article
Similar Reads