multiply two vectors, component by component


Would like to take two vectors and multiply components at the same index.For example {a1, a2, a3} x {b1, b2, b3} to produce {a1 b1, a2 b2, a3 b3}. The following works, but are there some alternatives?

aMat = DiagonalMatrix[{a1, a2, a3}];
bMat = DiagonalMatrix[{b1, b2, b3}];
Diagonal @ Dot[aMat, bMat] 
result: {a1 b1, a2 b2, a3 b3}


Posted 2018-09-08T19:18:16.660

Reputation: 925

Question was closed 2018-09-12T21:02:03.873

1{a1,a2,a3}*{b1,b2,b3} will give the required answer – mikado – 2018-09-08T19:22:04.623



No need to do anything fancy. This is just how ordinary list multiplication works:

{a1, a2, a3} {b1, b2, b3}


{a1 b1, a2 b2, a3 b3}

John Doty

Posted 2018-09-08T19:18:16.660

Reputation: 11 607

thanks! didn't even think to try that. – user6546 – 2018-09-08T19:25:15.813