# Using Sum on a list of data

i have 3 lists called Fi,Ti and Si, that go from 1 to 17. Each i corresponds to a certain value, i.e.

f = {0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 1, 2, 3, 4, 5, 6, 7, 8, 10};
Ta = {1, 1, 1, 1, 1.05, 1.15, 1.3, 1.5, 1.7, 1.9, 1.1, 0.5, 0.01, 0.001, 0.001, 0.001, 0.001}
Sui = {0.00126182, 0.00126182, 0.00126182, 0.00126181,
0.0012618, 0.00126178, 0.00126175, 0.00126172, 0.00126153, 0.00126064, 0.00125915, 0.00125708, 0.00125443, 0.0012512, 0.00124742, 0.00124308};


I am trying to compute the sum of the image attached (tried to paste the equation, but doesn't show in a mathematical form). Sorry my first time posting a question. Any advice ?

• How are you defining fn,tn? – Feyre Aug 26 '16 at 18:18
• fdata = {0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 1, 2, 3, 4, 5, 6, 7, 8, 10} and Ta = {1, 1, 1, 1, 1.05, 1.15, 1.3, 1.5, 1.7, 1.9, 1.1, 0.5, 0.01, 0.001, 0.001, 0.001, 0.001} – St LFC Aug 26 '16 at 18:23
• Please include all the needed information, including su, in your question itself. – bbgodfrey Aug 26 '16 at 18:44

Given (I added an extra element to Su as it seemed to be one short)

f = {0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 1, 2, 3, 4, 5,
6, 7, 8, 10};
Ta = {1, 1, 1, 1, 1.05, 1.15, 1.3, 1.5, 1.7, 1.9,
1.1, 0.5, 0.01, 0.001, 0.001, 0.001, 0.001};
Su = {0.00126182, 0.00126182, 0.00126182, 0.00126181, 0.0012618, 0.00126178,
0.00126175, 0.00126172, 0.00126153, 0.00126064, 0.00125915,
0.00125708, 0.00125443, 0.0012512, 0.00124742, 0.00124308, 0.001};


The "Mathematica" way is

Total[Differences[f] (Drop[Su Ta^2, -1] + Drop[Su Ta^2, 1])]/2
(* 0.0104223 *)


The literal way is

Sum[1/2 (f[[i + 1]] - f[[i]]) (Su[[i]] Ta[[i]]^2 + Su[[i + 1]] Ta[[i + 1]]^2), {i, 1, 16}]
(* 0.0104223 *)

• yep, i forgot the last element. it was: 0.0012328. Nevermind. Thanks a lot for your help. Appreciate it. Gonna look through these commands to fully understand it. – St LFC Aug 26 '16 at 19:17

Don't use subscripts for this kind of thing, they are best at display. You can directly index into your arrays:

Total[0.5 Table[(f[[i + 1]] - f[[i]]) (su[[i]] Ta[[i]]^2 +
su[[i + 1]] Ta[[i+1]]^2), {i, 1, Length[f] - 2}]]

• Why Length[f]-2 shouldn't it be Length[f]-1? – mikado Aug 26 '16 at 19:11
• worked. thanks a lot for your help and fast reply. I would like to add a "newbie" question. Which is the role of the gaps in-between the equation u posted ? e.g. (f[[i+1]] - f[[i]]) GAP (su[[i]] GAP Ta[[i]]^2 .... – St LFC Aug 26 '16 at 19:12
• @bill s, isn't putting Total round a Table redundant? Wouldn't Sum be better? – mikado Aug 26 '16 at 19:20
• The gaps (spaces) are multiplication. I tend to use Total[Table[ ]] rather than Sum[ ] because it is easy to look at the elements of the Table and make sure they are correct. But yes, you can save a few characters with Sum. – bill s Aug 26 '16 at 20:45

You just need to use the Subscript form of Part. I have used ta and su since you should not begin variables with a capital letter. I also added 0.001 to the end of su as it only has 16 entries.

Or in InputForm

Sum[(1/2)*(f[[i + 1]] - f[[i]])*(su[[i]]*ta[[i]]^2 +
su[[i + 1]]*ta[[i + 1]]^2), {i, 1, 16}]


You can enter the subscript form of Part by surrounding the indices in the subscript with the part double square brackets. Either [[ and ]] or Esc+[[+Esc and Esc+]]+Esc.

Hope this helps.