4
$\begingroup$

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}
$\endgroup$
1
  • 1
    $\begingroup$ {a1,a2,a3}*{b1,b2,b3} will give the required answer $\endgroup$
    – mikado
    Commented Sep 8, 2018 at 19:22

1 Answer 1

8
$\begingroup$

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

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

yields

{a1 b1, a2 b2, a3 b3}
$\endgroup$
1
  • $\begingroup$ thanks! didn't even think to try that. $\endgroup$
    – user6546
    Commented Sep 8, 2018 at 19:25

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