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


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

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)$$


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


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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