knitr::opts_chunk$set( warning = FALSE, message = FALSE, fig.height = 5, fig.width = 5 ) options(digits=4) par(mar=c(3,3,1,1)+.1)
The following examples illustrate the basic properties of the determinant of a matrix. We do this first with simple numerical examples and then using geometric diagrams.
A <- matrix(c(3, 1, 2, 4), nrow=2, byrow=TRUE) A det(A)
det(A[ 2:1, ]) det(A[, 2:1 ])
det( t(A) )
Note that to multiply rows by different constants requires a diagonal matrix on the left.
diag(c(3, 1)) %*% A det( diag(c(3, 1)) %*% A)
This is because multiplying a matrix by a constant multiplies each row.
det(3 * A) 3^2 * det(A)
The determinant of a product is the product of the determinants. The same holds for any number of terms in a matrix product.
B <- matrix(c(4, 2, 3, 5), nrow=2, byrow=TRUE) B det(A %*% B) det(A) * det(B)
det() == 0
Here we just add an additional copy of column 1 of a matrix, so C[,3] == C[,1]
.
The determinant is 0 because the columns are linearly dependent.
C <- matrix(c(1, 5, 2, 6, 4, 4), nrow=3, byrow=TRUE) C <- cbind(C, C[,1]) C det(C)
This is the principle behind one of the elementary row operations.
A[2,] <- A[2,] - 2*A[1,] det(A)
Many aspects of matrices and vectors have geometric interpretations. For $2 \times 2$ matrices, the determinant is the area of the parallelogram defined by the rows (or columns), plotted in a 2D space. (For $3 \times 3$ matrices, the determinant is the volume of a parallelpiped in 3D space.)
A <- matrix(c(3, 1, 2, 4), nrow=2, byrow=TRUE) A det(A)
The matlib
package has some handy functions (vectors()
) for drawing geometric diagrams.
#| fig.alt: A diagram showing two vectors, a1 and a2, illustrating that the area of the parallelogram they form is the determinant of the matrix with columns a1 and a2 library(matlib) xlim <- c(0,6) ylim <- c(0,6) par(mar=c(3,3,1,1)+.1) plot(xlim, ylim, type="n", xlab="X1", ylab="X2", asp=1) sum <- A[1,] + A[2,] # draw the parallelogram determined by the rows of A polygon( rbind(c(0,0), A[1,], sum, A[2,]), col=rgb(1,0,0,.2)) vectors(A, labels=c("a1", "a2"), pos.lab=c(4,2)) vectors(sum, origin=A[1,], col="gray") vectors(sum, origin=A[2,], col="gray") # add some annotations text(0,6, "det(A) is the area of its row vectors", pos=4) text(mean(A[,1]), mean(A[,2]), "det(A)", cex=1.25)
There is a simple visual proof of this fact about determinants but it is easiest to see in the case of a diagonal matrix, where the row vectors are orthogonal, so area is just height x width.
(D <- 2 * diag(2)) det(D)
Plot this as before:
#| fig.alt: A diagram showing two orthogonal vectors, d1 and d2 (at right angles). The determinant of the matrix containing them is the area of the square they form. par(mar=c(3,3,1,1)+.1) plot(c(0,2), c(0,2), type="n", xlab="X1", ylab="X2", asp=1) sum <- D[1,] + D[2,] polygon( rbind(c(0,0), D[1,], sum, D[2,]), col=rgb(0,1,0,.2)) vectors(D, labels=c("d1", "d2"), pos.lab=c(3,4)) vectors(sum, origin=D[1,], col="gray") vectors(sum, origin=D[2,], col="gray") text(mean(D[,1]), mean(D[,2]), "det(D)", cex=1.25)
Finally, we can also see why the determinant is zero when the rows or columns are proportional.
(B <- matrix(c(1, 2, 2, 4), 2,2)) det(B)
Such vectors are called collinear. They enclose no area.
#| fig-alt: A diagram showing two collinear (proportional) vectors, b1 and b2. The determinant of the matrix containing them is zero. par(mar=c(3,3,1,1)+.1) plot(c(0,4), c(0,4), type="n", xlab="X1", ylab="X2", asp=1) vectors(B, labels=c("b1", "b2"), pos.lab=c(4,2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.