# Get decomposition of vector in basis

Hey!

I have a matrix that represents my basis (it's actually a lattice so the vectors are rows, but it's not important I can transpose)

I have a vector aa in a canonical basis, I want to know what's the linear combination in R of my lattice's vectors that gives my vector aa

edit retag close merge delete

Sort by » oldest newest most voted

This is not very specific to Sage: if $M$ is the matrix whose columns $C_0,...,C_{n-1}$ represent your basis expressed in the canonical basis, you have $MX=aa$ where $X$ is a column vector, whose entries $x_0,...x_{n-1}$ correspond to the coefficients of the linear combination you are looking for, that is $aa = x_0C_0+...+x_{n-1}C_{n-1}$ .

So, if you want to find $X$ you just have to compute:

sage: X = M^(-1)*aa


Then, if you want to manipulate the coefficients $x_i$ as in a list, you can do:

sage: L = X.list()

more