A First Course in Linear Algebra, Beezer, R., 2008
Question C23 page 278:
Doing the computations by hand, find the determinant of the matrix
below.
1 3 2
4 1 3
1 0 1
Define matrix
Below a 3x3 matrix is coded and printed.
A <- matrix(c(1, 4, 1, 3, 1,0 ,2 ,3 ,1 ), nrow = 3, byrow = FALSE)
print(A)
## [,1] [,2] [,3]
## [1,] 1 3 2
## [2,] 4 1 3
## [3,] 1 0 1
Code the coordinates
Below the coordinates are coded to prepare for determinant
calculation.
a11<-A[1,1]
a12<-A[1,2]
a13<-A[1,3]
a21<-A[2,1]
a22<-A[2,2]
a23<-A[2,3]
a31<-A[3,1]
a32<-A[3,2]
a33<-A[3,3]
Determinant calculation
This is the determinant calculation.
#Calculation
D_a<- (a11*a22*a33) +
(a21*a32*a13) +
(a31*a12*a23) -
(a13*a22*a31) -
(a23*a32*a11) -
(a31*a12*a21)
print(D_a)
## [1] -4
Proof
I validated the above calculation was correct by using the det()
function.
Both the manual calucation and the function equal -4
D_a_validate <- det(A)
D_a_validate
## [1] -4