To find the determinant of a matrix in R, you can use the det()
function. This function takes a matrix as input and returns its determinant.
In this example,
matrix1
using the matrix()
function with a vector of values c(1, 2, 3, 4)
and specify the number of rows as 2.det()
function on matrix1
and store the result in a variable called determinant1
.det()
function computes the determinant of the matrix using its values.print()
function to display the determinant stored in determinant1
.matrix1 <- matrix(c(1, 2, 3, 4), nrow = 2)
determinant1 <- det(matrix1)
print(determinant1)
[1] -2
In this example,
matrix2
using the matrix()
function with a vector of values c(1, 2, 3, 4, 5, 6, 7, 8, 9)
and specify the number of rows as 3.det()
function on matrix2
and store the result in a variable called determinant2
.det()
function computes the determinant of the matrix using its values.print()
function to display the determinant stored in determinant2
.matrix2 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow = 3)
determinant2 <- det(matrix2)
print(determinant2)
[1] 0
In this example,
matrix3
using the matrix()
function with a vector of values c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160)
and specify the number of rows as 4.det()
function on matrix3
and store the result in a variable called determinant3
.det()
function computes the determinant of the matrix using its values.print()
function to display the determinant stored in determinant3
.matrix3 <- matrix(c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160), nrow = 4)
determinant3 <- det(matrix3)
print(determinant3)
[1] 0
In this tutorial, we learned How to find Determinant of a Matrix in R language with well detailed examples.