# Generating a vector basis

I have several lists parameterizing a vector space, for instance

{a[1],a[2],a[1]+2 a[2]-a[3]}


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

{a[1],a[2],a[1]+2 a[2]-a[3]} == a[1] {1,0,1} + a[2] {0,1,2 } + a[3] {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[1], a[2], a[1] + 2 a[2] - a[3]}, #] &, Table[a[i], {i, 3}]]
(*{{1, 0, 1}, {0, 1, 2}, {0, 0, -1}}*)


CoefficientArrays[] does nicely for this:

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

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


This is very short:

vec = {a[1], a[2], a[1] + 2 a[2] - a[3]};

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.