# Generating a vector basis

I have several lists parameterizing a vector space, for instance

{a,a,a+2 a-a}


For each list I want to generate a basis such as {{1,0,1},{0,1,2},{0,0,-1}} so that

{a,a,a+2 a-a} == a {1,0,1} + a {0,1,2 } + a {0,0,-1 }


The function Position[] does not look helpful for this.

• What are the a's supposed to be, basis vectors? Jul 10, 2016 at 21:00
• No, the a's are coefficients. Jul 10, 2016 at 21:01
• I think you jumped quite a bit; I'm not seeing how your coefficients map to basis vectors. Jul 10, 2016 at 21:05

Try something like this:

Map[Coefficient[{a, a, a + 2 a - a}, #] &, Table[a[i], {i, 3}]]
(*{{1, 0, 1}, {0, 1, 2}, {0, 0, -1}}*)


CoefficientArrays[] does nicely for this:

CoefficientArrays[{a, a, a + 2 a - a}, Array[a, 3]] //
Normal // Last // Transpose

{{1, 0, 1}, {0, 1, 2}, {0, 0, -1}}


This is very short:

vec = {a, a, a + 2 a - a};

Transpose[D[vec, {Array[a, 3]}]]

(* ==> {{1, 0, 1}, {0, 1, 2}, {0, 0, -1}} *)


It gets the basis from the columns of the Jacobian for the linear relation in vec.