Print intermediate result Sum function

Viewed 150

I write simple code in Wolfram Mathematica:

x = 2
k = 0
n = 15
total = Sum[((-1^k)*(x^(4*k + 1))) / (((2*k)!) * (4*k + 1)), k, n]

I want print result (the sum all members) and print all(!!!) intermediate results function Sum. How this make?

2 Answers

Try

x=2;k=0;n=15;
Table[((-1^k)*(x^(4*k+1)))/(((2*k)!)*(4*k+1)),{k,n}]

That gives you a list of 15 elements.

Notice that I changed k,n to {k,n}.

Then Total[%] will add those to create a sum.

Your syntax is calculating a multiple indefinite sum, e.g.

Sum[Defer[g + h], g, h]

https://en.wikipedia.org/wiki/Indefinite_sum

If you add brackets around k, n you will obtain the sum Bill's answer shows.

total = Sum[((-1^k)*(x^(4*k + 1)))/(((2*k)!)*(4*k + 1)), {k, n}]
Related