# Revision history [back]

Basic linear algebra is easily done with matrices. Let me replace 20 by 3 (in my example) and assume that your set of 3 linearly independent vectors are stored in a list L:

sage: L = []
sage: L.append(vector(QQ,[1,2,3]))
sage: L.append(vector(QQ,[0,3,1]))
sage: L.append(vector(QQ,[0,0,2]))

sage: L
[(1, 2, 3), (0, 3, 1), (0, 0, 2)]


Then, you define the matrix M whose columns are the vectors of L:

sage: M = matrix(L).transpose()
sage: M
[1 0 0]
[2 3 0]
[3 1 2]


sage: V = vector(QQ,[1,1,2]) ; V
(1, 1, 2)


The linear combination you are looking for is given by $M^{-1}V$:

sage: W = M.inverse()*V ; W
(1, -1/3, -1/3)


Which you can check with:

sage: sum(W[i]*L[i] for i in range(3))
(1, 1, 2)
sage: sum(W[i]*L[i] for i in range(3)) == V
True