# Summation exercise — how can I translate the problem statement into the Wolfram Language? [closed]

I'm new to both Mathematica and this forum, so this will be my first post here. I just got into Mathematica today, and I've been doing some exercises. Up to now things have been going well, but I've become stuck on this specific exercise:

Calculate the sum, use Sum, N. You have to convert the number to a floating point number in order to recognize it. $$4\sum_{k=1}^{1000}\frac{(-1)^{k+1}}{2k-1}$$

What I do not understand is exactly what the Sum function should look like. Also, do I convert the answer I get to a floating point number with N?

• Also 4 NSum[(-1)^(k + 1)/(2 k - 1), {k, 1, 1000}]. You should be able to recognise the number yourself, but if you don't, use 4 Sum[(-1)^(k + 1)/(2 k - 1), {k, 1, ∞}]. – AccidentalFourierTransform Nov 1 '18 at 17:00
• This was x-posted on Wolfram Community: community.wolfram.com/groups/-/m/t/1540588 (note to poster: when you do that, please add links from each to the other, so that potential responders will know what has already been covered). – Daniel Lichtblau Nov 1 '18 at 17:06
• Look also at RootApproximant[sum/Pi] Pi – Bob Hanlon Nov 2 '18 at 0:45

Although you explicitly asked about using Sum, please note an alternative way to approach calculating the same thing, without any explicit use of an iterator {i, 1000}:

f[x_] := 10^(x + 1)/(2 x - 1)
N[Total[f[Range[1000]]]]
(* 5.558953381284399*10^997 *)


This is possible because f automatically gets the attribute of being Listable, so that f[Range[1000]] finds "simultaneously" the value of f at all the entries in the list Range[1000].

You can avoid all the nested brackets above (which make it hard to read) by using the Prefix operator abbreviated by @:

N @ Total @ f@ Range[1000]


I think the exercise should go this way.

 Sum[(-1)^(k + 1)/(2 k - 1), {k, 1000}] // N


0.785148

This is an approximation of π/4 as can be inferred from

sum = Sum[(-1)^(k + 1)/(2 k - 1), {k, ∞}]


π/4

and

N[sum]


0.785373

You can look up usage etc. of functions in the documentation. eg.: https://reference.wolfram.com/language/ref/Sum.html

In other words you need to write

Sum[f[i], {i,1000}]


with f being your function. N can just be applied the yield a number. Refer to the Documentation for further information or feel free to ask me.

• Thank you for your reply. The way I solved this was by creating a variable and setting it equal to the Sum[] function, and then just typing N[variable], much like in programming. Is that acceptable? – wznd Nov 1 '18 at 14:43
• Yes, N[x] is the same as N@x is the same as x // N (postfix should only be followed by other postfixes) – Gladaed Nov 2 '18 at 13:03

This is easy to understand if you use the Mathematica help pages for Sum and N. I don't understand what you mean by converting the number to a floating point number.

Start by defining

f[x_] := 10^(x + 1)/(2 x - 1)


Then use:

Sum[f[i], {i, 1000}]


You get a very big number.

Then type

N[%]


and you will get the number in floating point format. I get

5.558953381284399*10^997

• You are right. The thing that confused me was the instruction to convert the sum into a floating point number, since the sum of the function is very long. I used sumLargeValue = 4 *Sum[(-1^(k + 1))/(2 k - 1), {k, 1000}] and then I used N[sumLargeValue] to print the floating point sum. – wznd Nov 1 '18 at 14:39