QuestionSum!!
Moderators: gmalivuk, Moderators General, Prelates
QuestionSum!!
Hello !! I noticed,by writing a program in c,that,calculating a sum backwards gives a better approximation of the real value of the sum than calculating it forwards..Why does this happen???
Re: QuestionSum!!
What do you mean?
Order of the sum as in "double x = 5.3+4.7;" is giving you a different number than "double x = 4.7+5.3;"?
It might be worthwhile to post an example of the code that's giving odd results.
(Also, I suspect this is gonna end up being more of a coding type question than math, with an answer either being an issue with how numbers are represented underthehood or an outright coding error, rather than an unusual aspect of math itself at play.)
Order of the sum as in "double x = 5.3+4.7;" is giving you a different number than "double x = 4.7+5.3;"?
It might be worthwhile to post an example of the code that's giving odd results.
(Also, I suspect this is gonna end up being more of a coding type question than math, with an answer either being an issue with how numbers are represented underthehood or an outright coding error, rather than an unusual aspect of math itself at play.)

 Posts: 109
 Joined: Wed Apr 24, 2013 1:33 am UTC
Re: QuestionSum!!
It is probably related to the floating point representation of reals but that should happen only on some particular sums, can you show us exactly which sum(s) are you speaking about?
The primary reason Bourbaki stopped writing books was the realization that Lang was one single person.
Re: QuestionSum!!
If you are trying to add a wide range of fixedprecision numbers together, it's better to start with the small ones and finish with the big: Crudely speaking, adding the small ones together gives them a chance to become big, and so add to the big numbers correctly  whereas starting big and then adding small, the small ones will just get ignored.
See a thread like this for how to add numbers together with perfect precision: http://stackoverflow.com/questions/3941 ... ntnumbers
See a thread like this for how to add numbers together with perfect precision: http://stackoverflow.com/questions/3941 ... ntnumbers
Re: QuestionSum!!
alessandro95 wrote:It is probably related to the floating point representation of reals but that should happen only on some particular sums, can you show us exactly which sum(s) are you speaking about?
The sum I am referring to is: Σ_{k=1}^{n}{1/k^2}.
Why is the approximation better at the backward sum in this case?
 ahammel
 My Little Cabbage
 Posts: 2135
 Joined: Mon Jan 30, 2012 12:46 am UTC
 Location: Vancouver BC
 Contact:
Re: QuestionSum!!
He was probably asking you to post code snippets that give different results when you sum the same numbers in different order.mathmari wrote:The sum I am referring to is: Σ_{k=1}^{n}{1/k^2}.
Why is the approximation better at the backward sum in this case?
He/Him/His/Alex
God damn these electric sex pants!
Re: QuestionSum!!
mathmari wrote:The sum I am referring to is: Σ_{k=1}^{n}{1/k^2}.
Why is the approximation better at the backward sum in this case?
Because going backwards adds small numbers before big numbers (see my previous post).
Btw: Two threads, both posted on the same day, both querying why the same series sums differently forwards to backwards? Homework? viewtopic.php?f=17&t=106157#p3487968
 gmalivuk
 GNU Terry Pratchett
 Posts: 26577
 Joined: Wed Feb 28, 2007 6:02 pm UTC
 Location: Here and There
 Contact:
Re: QuestionSum!!
Yeah, this looks like it's a question about something brought up in that other thread, which means any further discussion of it can happen in that other thread as well.
Who is online
Users browsing this forum: No registered users and 13 guests