2
$\begingroup$

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.

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

3 Answers 3

3
$\begingroup$

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}}*)
$\endgroup$
6
$\begingroup$

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}}
$\endgroup$
5
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.