Dimension of vector space is number of basis vectors which spans the given vector space.
Dimension of Null Space of a given matrix is called nullity. It can be denoted as nullity(B).
We can calculate nullity of a matrix by reducing matrix into row echelon form, and then count number of free variables.
Dimension of column space of a matrix is called rank of matrix. Rank of a matrix can be calculated similarly, by reducing the given matrix into row echelon form and then calculating pivot variables.
In this brief tutorial, I demonstrate how to calculate Nullity and Rank in R. While there are various methods to achieve these results, I believe this basic approach can be particularly helpful for high school students, like my daughter, who are just beginning to learn linear algebra.
One final thing, which I would like to mention is that, number of columns of a matrix will equal to sum of rank and nullity.
B = matrix(c(5, 5, 3, 6, 1, 8, 4, 1, 6, 2, 1, 2), nrow = 3, byrow = TRUE)
B
## [,1] [,2] [,3] [,4]
## [1,] 5 5 3 6
## [2,] 1 8 4 1
## [3,] 6 2 1 2
pracma::rref(B)
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0.3043478
## [2,] 0 1 0 -3.9565217
## [3,] 0 0 1 8.0869565
Number of pivot variables are three, and we have one free variable in the matrix. Therefore rank of the matrix \(B\) is 3 and nullity equals 1.