2
$\begingroup$

This question already has an answer here:

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

$\endgroup$

marked as duplicate by Mr.Wizard Aug 1 '14 at 17:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

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}}
$\endgroup$
  • $\begingroup$ 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}] $\endgroup$ – DdS Aug 1 '14 at 19:28
1
$\begingroup$

You want CoefficientArrays:

CoefficientArrays[V, var] // Last // Normal
{{exp1, exp2, exp3}, {exp4, exp5, exp6}, {exp7, exp8, exp9}}
$\endgroup$

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