Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I convert expression a1*u1+a2*u2+a3*u3 to the vector form of dot product A.U, where A={a1,a2,a3} and U={u1,u2,u3}?

share|improve this question
up vote 5 down vote accepted

If you define :

expr=a1*u1 + a2*u2 + a3*u3;
aVec={a1, a2, a3};

then you can get

uVec=Coefficient[expr, aVec];

Dot[aVec, uVec]==expr
share|improve this answer

I think you may try


{a1, a2, a3}

where we get


a1 u1 + a2 u2 + a3 u3

This also works for system of equations.

{const, coeff} = Normal@
 a + x - y - z == 0, 
 b + x + 2 y + z == 0
 }, {x, y, z}];
 coeff. {x, y, z} + const

{a + x - y - z, b + x + 2 y + z}

See the important matrix


$$\left( \begin{array}{ccc} 1 & -1 & -1 \\ 1 & 2 & 1 \\ \end{array} \right)$$

share|improve this answer
Thank you all of you very much – SergeyFomin Sep 13 '12 at 9:04

I'm not sure if this is the correct way to interpret your question, but here goes.

You can separate the components of (a1*u1 + a2*u2 + a3*u3) into two vectors by the following:

vecs = Transpose[List @@@ (List @@ (a1*u1 + a2*u2 + a3*u3))]

{{a1, a2, a3}, {u1, u2, u3}}

The dot product can be formed:


a1 u1 + a2 u2 + a3 u3

share|improve this answer

Another approach (similar to image_doctor's) uses replacement rules rather than Apply. Observe that the internal representation is

 FullForm[a1*u1 + a2*u2 + a3*u3]


If we were to change the "Times" to "List" and change "Plus" to "List" then we'd be almost there:

prod=a1*u1 + a2*u2 + a3*u3 //. {Times -> List, Plus -> List}


All we need do is pick out the a's and u's separately. So we could define:

a = prod[[All, 1]];
u = prod[[All, 2]];

Then Dot[a, u] gives the original product.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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