2

I have a vector like this:

V = {a*exp1+b*exp2+c*exp3, a*exp4+b*exp5+c*exp6, a*exp7+b*exp8+c*exp9}

and I want to get :

mat = {{exp1, exp2, exp3}, {exp4, exp5, exp6}, {exp7, exp8, exp9}}

from vector

var = {a, b, c}

so : mat.var === V

Öskå
  • 8,587
  • 4
  • 30
  • 49
DdS
  • 23
  • 3

2 Answers2

2

Use Coefficient:

var = {a, b, c}
V = {a*exp1+b*exp2+c*exp3, a*exp4+b*exp5+c*exp6, a*exp7+b*exp8+c*exp9}    
Transpose[Map[Coefficient[V, #] &, var]]
{{exp1, exp2, exp3}, {exp4, exp5, exp6}, {exp7, exp8, exp9}}
Coolwater
  • 20,257
  • 3
  • 35
  • 64
  • Thats the solution Thanks! In case of Vector is in form: V = {{aexp1+bexp2+cexp3}, {aexp4+bexp5+cexp6}, {aexp7+bexp8+c*exp9}} Use Reshape[list_, dimensions_] := First[Fold[Partition[#1, #2] &, Flatten[list], Reverse[dimensions]]]; Reshape[Transpose[Map[Coefficient[V, #] &, var]],{3,3}] – DdS Aug 01 '14 at 19:28
2

You want CoefficientArrays:

CoefficientArrays[V, var] // Last // Normal
{{exp1, exp2, exp3}, {exp4, exp5, exp6}, {exp7, exp8, exp9}}
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371