Skip to main content
1 of 3
Azzurro94
  • 499
  • 2
  • 10

How to get Sum of array of integers?

This question seems easy but I am struggling with it now, I tried a few ways and check this solution as well but couldn't help me, please check and help if you are able:
So I need to save the sum of array elements in single variable and I tried these approaches, I show you two of them here. (I must have x as variable to store result, and initialize the array as well)

Array [A, 3]
A = {1, 2, 5}
R2 = x == Sum[A[index], {index, i, 3}]  && i == 1
Simplify[Reduce[R2]]

And Also

R2 = x == Sum[A[index], {index, i, 3}] && A[1] == 1 && A[2] == 2 && A[3] == 5 && i == 1
Simplify[Reduce[R2]]

this is part of final answer I get

x == A[1] + A[2] + A[3]

It shows me a simple equation not final answer, but I expect a simple answer x== 8 or x-> 8, but it does not solve the SUM, seems I am missing something.

Azzurro94
  • 499
  • 2
  • 10