#install.packages('pracma')
#library('pracma')

C29 pg. 354 Alt text

A = cbind(c(2,0,0,0,0), c(3,1,0,1,0), c(0,1,1,2,0), c(2,1,2,1,1), c(1,2,3,0,2))
I = diag(5)
# convert A to upper triangular matrix U and then determinant is the product of diagonal entries
# To do this I will use elimination matrices
# setup U to do elimation matrices on
U = A
print('first column clear under diagonal')
## [1] "first column clear under diagonal"
print(U)
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2    3    0    2    1
## [2,]    0    1    1    1    2
## [3,]    0    0    1    2    3
## [4,]    0    1    2    1    0
## [5,]    0    0    0    1    2
E1 = I
E1[4,2] = -1 #-1R2 + R4 to clear out column 2 under the diagonal
U = E1 %*% U
print('clear the 1 at U[4,2]')
## [1] "clear the 1 at U[4,2]"
print('second column clear under diagonal')
## [1] "second column clear under diagonal"
U
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2    3    0    2    1
## [2,]    0    1    1    1    2
## [3,]    0    0    1    2    3
## [4,]    0    0    1    0   -2
## [5,]    0    0    0    1    2
E2 = I
E2[4,3] = -1 #-1R3 + R4 to clear out column 3 under the diagonal
U = E2 %*% U
print('clear the 1 at U[4,3]')
## [1] "clear the 1 at U[4,3]"
print('third column clear under diagonal')
## [1] "third column clear under diagonal"
U
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2    3    0    2    1
## [2,]    0    1    1    1    2
## [3,]    0    0    1    2    3
## [4,]    0    0    0   -2   -5
## [5,]    0    0    0    1    2
E3 = I
E3[5,4] = .5 #.5R4 + R5 to clear out column 4 under the diagonal
U = E3 %*% U
print('clear the 1 at U[5,4]')
## [1] "clear the 1 at U[5,4]"
print('fourth column clear under diagonal')
## [1] "fourth column clear under diagonal"
U
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2    3    0    2  1.0
## [2,]    0    1    1    1  2.0
## [3,]    0    0    1    2  3.0
## [4,]    0    0    0   -2 -5.0
## [5,]    0    0    0    0 -0.5
print('determinant is product of diagonal elements of U')
## [1] "determinant is product of diagonal elements of U"
det = prod(diag(U))
det
## [1] 2

Compare to built-in functions

det(A)
## [1] 2