I would like a time efficient way to calculate a sum of the following form:
y = ConstantArray[0,5];
x = {x1, x2, x3, x4, x5};
j = 2;
For[i = 1, i <= 5, i++,
y[[i]] = x[[i]] + Sum[x[[n - 1]]*Exp[Sum[x[[m - 1]], {m, n, i}], {n, j, i}]
]
This produces an output of the following form:
{x1,
x1*Exp[x1] + x2,
x1*Exp[x1 + x2] + x2*Exp[x2] + x3,
x1*Exp[x1 + x2 + x3] + x2*Exp[x2 + x3] + x3*Exp[x3] + x4,
x1*Exp[x1 + x2 + x3 + x4] + x2*Exp[x2 + x3 + x4] + x3*Exp[x3 + x4] + x4*Exp[x4] + x5}
I would like to perform this sort of calculation for an array of about 300,000 data points to simulate cumulative decay. I am aware of the limitations of the Sum function with regards to computational speed, but I am struggling to recreate this sort of output structure with other functions such as Total or Accumulate. Can anyone suggest a better way?