Skip to main content
3 of 4
added Table example

Create lists like this:

g = {1, 2, 3, 4}
h = {10, 20, 30, 40}

Then you can sum like this:

Sum[g[[i]] h[[i]], {i, Length[g]}]

or more nicely (Mathematica does element-wise operations automatically where applicable):

Total[g*h]

You can use this feature to easily calculate a new list with the results, without using indices:

f = (g h)/Total[g h]

{1/30, 2/15, 3/10, 8/15}

If you want to use indices anyway, you can do it with Table:

f1 = Table[
  (g[[k]] h[[k]])/Sum[g[[i]] h[[i]], {i, Length[g]}],
  {k, Length[g]}]