# How to evaluate the sum using values from the data being input

I have a problem in evaluating a sum using values from data I input.

Suppose I have data = {1, 3, 5, 6, 8}

If I want to evaluate the sum of my data (1+3+5+6+8), I can use the following command:

Sum[x, {x, data}]


And it will give me 23, which is correct.

However, I found difficulty if I want to evaluate the sum of Log of each value, such that I have: Log(1) + Log(3) + Log(5) + Log(6) + Log(8). This can be done manually if I type the function one by one, but then it is not efficient if I have 100 values to be calculated. Can anyone help me in solving this problem?

-
Something like Total[Log[data]]? –  J. M. is back. Oct 18 '12 at 12:39
and if you want to stick to your strategy Sum[x,{x,Log[data]}] –  chris Oct 18 '12 at 12:55

For the sum it's much better to use Total

Total@data
(*23*)


for the Logs, you can use the fact that Log is Listable and write

Total@Log@data
(*Log[3] + Log[5] + Log[6] + Log[8]*)


(if you need a numerical value just use N)

-

You can still you Sum, but you are now summing $\sum_{x \in \text{data}}\log(x)$ rather than $\sum_{x \in \text{data}}x$:

In[367]:= data = {1, 3, 5, 6, 8};
Sum[Log[x], {x, data}]

Out[368]= Log[3] + Log[5] + Log[6] + Log[8]

In[369]:= Total[Log[data]]

Out[369]= Log[3] + Log[5] + Log[6] + Log[8]

-
Sasha, you're back! I hope you stay around this time. :-) –  Mr.Wizard Oct 18 '12 at 12:59