# How do I generate and sum the products of corresponding components of n vectors?

As an example, consider the three vectors:

{b1, b2, b3}, {h1, h2, h3}, {yc1, yc2, yc3}.

How do I get b1*h1*yc1 + b2*h2*yc2 + b3*h3*yc3 ?

I mean to get the sum of the products of the corresponding components of all vectors.

• Total[{b1, b2, b3} {h1, h2, h3} {yc1, yc2, yc3}] Commented Apr 30, 2020 at 17:19
• Nice thank you very much! I just got on Mathematica recently. Commented Apr 30, 2020 at 17:22

a = {b1, b2, b3};
b = {h1, h2, h3};
c = {yc1, yc2, yc3};
(a b).c

(* b1 h1 yc1 + b2 h2 yc2 + b3 h3 yc3 *)
a = {b1, b2, b3};
b = {h1, h2, h3};
c = {y1, y2, y3};

Plus @@ Times @@ {a, b, c}

b1 h1 y1 + b2 h2 y2 + b3 h3 y3

a = {b1, b2, b3};
b = {h1, h2, h3};
c = {y1, y2, y3};

or

Using Fold:

Plus @@ Fold[Times, {a, b, c}]

Result:

b1 h1 yc1 + b2 h2 yc2 + b3 h3 yc3

a = {b1, b2, b3};
b = {h1, h2, h3};
c = {y1, y2, y3};

Using Outer:

Total@Nest[Diagonal, Outer[Times, a, b, c], 2]

(*b1 h1 y1 + b2 h2 y2 + b3 h3 y3*)
☺ = +## & @@ (1 ##) &;

☺[{b1, b2, b3}, {h1, h2, h3}, {yc1, yc2, yc3}]
b1 h1 yc1 + b2 h2 yc2 + b3 h3 yc3