Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 109
The first two cells below show how to check whether a given set of vectors is linearly independent.
# Sec. 7.3, exercise 10: Check for linear in/dependence of the vectors # x_1=(1, 2, -1, 0); x_2=(2, 3, 1, -1); x_3=(-1, 0, 2, 2); x_4=(3, -1, 1, 3) # # METHOD 1 # Check whether the matrix of column vectors (x_1, x_2, x_3, x_4) # is non-singular. Note: since we can only check non-singular # for square matrices, this method is limited to cases # where # of vectors = # of dimension of vector-space. x1 = vector( [1, 2, -1, 0] ) x2 = vector( [2, 3, 1, -1] ) x3 = vector( [-1, 0, 2, 2] ) x4 = vector( [3, -1, 1, 3] ) A = matrix( [x1, x2, x3, x4]) # define matrix of column vectors det(A) # compute its determinant
70-70
# METHOD 2 # Create a "free module" of dimension 4 and define the vectors # in that vector space/free module. Then use the builtin # attribute "are_linearly_dependent" to get true/false. M = QQ^4 # Creates a "free module" of dimension 4 over the field of rationals v1 = M( [1, 2, -1, 0] ) # Defines the vectors in the vector space/free module M v2 = M( [2, 3, 1, -1] ) v3 = M( [-1, 0, 2, 2] ) v4 = M( [3, -1, 1, 3] ) M.are_linearly_dependent([v1, v2, v3, v4]) # Check whether the vectors are linearly dependent
False\mathrm{False}
Let's modify the above example and address cases where the number of vectors does not equal the dimensions of the vector space.

We will consider both possibilities: (1) fewer vectors than dimensions; and (2) more vectors than dimensions.
# Case 1: Fewer vectors than dimensions. # Sec. 7.3, modify exercise 10: Check for linear in/dependence of # the first 3 vectors x_1=(1, 2, -1, 0); x_2=(2, 3, 1, -1); x_3=(-1, 0, 2, 2). # We know from the previous exercise that they must be # linearly independent. # Let's check for this by forming the matrix of column vectors # and then row-reducing it to reduced echelon form: x1 = vector( [1, 2, -1, 0] ) x2 = vector( [2, 3, 1, -1] ) x3 = vector( [-1, 0, 2, 2] ) Ashort = transpose( matrix( [x1, x2, x3]) ) # define matrix of column vectors Ashort.rref() # reduced echelon form print "\n Since every row has diagonal entry 1, they are linearly independent"
(100010001000)\left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \end{array}\right)
Since every row has diagonal entry 1, they are linearly independent
# Case 2: More vectors than dimensions. # Sec. 7.3, modify exercise 10: Check for linear in/dependence of # the 5 vectors x_1=(1, 2, -1, 0); x_2=(2, 3, 1, -1); x_3=(-1, 0, 2, 2); # x_4=(3, -1, 1, 3); x_5=(0, -1, -2, 3). # A set of 5 vectors in 4 dimensions will always be # linearly dependent. x1 = vector( [1, 2, -1, 0] ) x2 = vector( [2, 3, 1, -1] ) x3 = vector( [-1, 0, 2, 2] ) x4 = vector( [3, -1, 1, 3] ) x5 = vector( [0, -1, -2, 3] ) Als = transpose( matrix( [x1, x2, x3, x4, x5]) ) # define matrix of column vectors Als.rref()
[ 1 0 0 0 57/35] [ 0 1 0 0 -9/7] [ 0 0 1 0 9/35] [ 0 0 0 1 2/5]
# Verify (57/35)*x1 - (9/7)*x2 + (9/35)*x3 + (2/5)*x4
(0, -1, -2, 3)
# Example showing how to row-reduce a matrix to echelon form. # (There is also some miscellaneous other stuff mixed in below.) # Note that when the matrix is singular, I don't get the general # parametric form of the solution of A*X = 0. Instead it returns X=0. A1 = matrix([ [3,-6], [-1, 2] ]) Y1 = vector([0, 0]) print A1, Y1 #X1 = A1\Y1 #print X1 #print det(A1) #A1.echelon_form() # plain echelon form A1.rref() # reduced echelon form
[ 3 -6] [-1 2] (0, 0) [ 1 -2] [ 0 0]
# Another example of row-reduction, this time with a rectangular matrix. A2 = matrix([ [3,-6, 4], [-1, 2, 5]]) Y2 = vector([0, 0]) print A2, Y2 X2 = A2\Y2 print X2 #A2.echelon_form() A2.rref()
[ 3 -6 4] [-1 2 5] (0, 0) (0, 0, 0) [ 1 -2 0] [ 0 0 1]
# Yet another example of row-reduction, again with a rectangular matrix. A3 = matrix([ [1, 3, 5], [2, 4, 6]]) A3.rref()
[ 1 0 -1] [ 0 1 2]
# And some more... A4 = matrix([ [-1, 2], [0, 0], [2, -4]]) A4.rref()
[ 1 -2] [ 0 0] [ 0 0]
# Sec. 7.3, exercise 7 A5 = matrix([ [1, 0, 1], [1, 1, 0], [0, 1, 1]]) A5.rref()
[1 0 0] [0 1 0] [0 0 1]
A6 = matrix([ [1, 1, 3], [2, 1, 0] ]) A6.rref()
[ 1 0 -3] [ 0 1 6]