# how to extract a matrix and a vector from a vector [duplicate]

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

-

## 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.

## 2 Answers

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}}

-
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 1 '14 at 19:28

You want CoefficientArrays:

CoefficientArrays[V, var] // Last // Normal

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

-