This requires pracma again.

library("pracma")
## Warning: package 'pracma' was built under R version 3.4.1

Another this that I am curious about is if the vectors that span the subspace W are normal (perpendicular). If so, their dot products should be zero.

W1 <- matrix(c(1,2,-1,2), ncol = 1 , nrow = 4)
W2 <- matrix(c(1,0,3,1), ncol = 1 , nrow = 4)
W3 <- matrix(c(2,1,1,2), ncol = 1 , nrow = 4)
W1
##      [,1]
## [1,]    1
## [2,]    2
## [3,]   -1
## [4,]    2
W2
##      [,1]
## [1,]    1
## [2,]    0
## [3,]    3
## [4,]    1
W3
##      [,1]
## [1,]    2
## [2,]    1
## [3,]    1
## [4,]    2

Now to find the dot products. Which pracma also has a function for.

dot(W1,W2)
## [1] 0
dot(W1,W3)
## [1] 7
dot(W2,W3)
## [1] 7

Since W2*W3 and W1*W3 are not zero this is not a normal basis for the subspace W.

Are these vectors Linearly independent? To test this we find the rref of W. We need to recreate W from it’s basis vectors.

W <- cbind(W1,W2,W3)
W
##      [,1] [,2] [,3]
## [1,]    1    1    2
## [2,]    2    0    1
## [3,]   -1    3    1
## [4,]    2    1    2

Now to find the rref. If it is L.I. then we should get a 3x3 Identity Matrix with 1 zero row.

rref(W)
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
## [4,]    0    0    0

So these vectors are at least L.I.