# Totalling a list including negative values [closed]

I'm trying to use the Total function on a list that includes negative values, and can't seem to figure out how to stop Mathematica from getting hung up on those values.

The Total function is part of a Do loop;

Do[index = (Ca[[i]] - Mean[Ca])*(Cb[[i]] - Mean[Cb]); (Total[index])/40, {i, 40}]


I get the following messages:

Total::normal: Nonatomic expression expected at position 1 in Total[-47.3332].

Total::normal: Nonatomic expression expected at position 1 in Total[-25.6954].

Total::normal: Nonatomic expression expected at position 1 in Total[-0.779181].

General::stop: Further output of Total::normal will be suppressed during this calculation.

I know that further down the index list there are positive values, which cause problems trying to use the solutions from the "Counting negative values in list" thread. I'm terribly sorry for such a beginner question, but I'm extremely hung up on this problem!

EDIT:

Ah, thank you so much Jonie, that was an increadibly beginner flaw in my loop design. I fixed it to

Lista = {}
Do[index = (Ca[[i]] - Mean[Ca])*(Cb[[i]] - Mean[Cb]);   AppendTo[Lista, index], {i, 40}]
Total[Lista]/40


And it works fine now. Much appreciate you taking the time to point that out!

-

## closed as off-topic by m_goldberg, Kuba, Sjoerd C. de Vries, Artes, Mr.Wizard♦Jul 22 '13 at 14:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, Kuba, Sjoerd C. de Vries, Artes, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

The problem isn't about Total being used on a negative value. It's because index is not a list of values so there's nothing to Total on. Hence you got the errors saying its expecting a nonatomic expression (expressions such as lists). –  Jonie Jul 22 '13 at 1:30
Give this a try Total[(Ca - Mean[Ca]) * (Cb - Mean[Cb])] –  Jonie Jul 22 '13 at 1:36

answer=(ca-Mean[ca]).(cb-Mean[cb])