erroneous result when adding reals
- To: mathgroup at smc.vnet.net
- Subject: [mg100853] erroneous result when adding reals
- From: Vlad Seghete <vlad.seghete at gmail.com>
- Date: Tue, 16 Jun 2009 21:51:42 -0400 (EDT)
Hi all, I'm fairly new to Mathematica and today I ran into an issue that confuses me endlessly. It has to do with simple addition of real numbers. It seems like adding x (anything) to 0. (the real) produces a result different from x, within something close to machine precision. The problem becomes more serious when I do the addition in a Do loop, like below: Module[{tnew, tcur = 0., h = 1/100}, Clear[ts]; ts = {tcur}; (* ts is a list *) Do[tcur = ts[[-1]]; tnew = tcur + h; (* add h to the last element of the list *) AppendTo[ts, tnew], (* and then push it at the end of the list *) {step, 1, 300} (* repead 300 times *) ] ]; ListLinePlot[Table[h, {h, 0, 3, 1/100}] - ts, InterpolationOrder -> 0] The plot I get is NOT constant, and the error introduced through the "real addition" done in the Do loop is systematic and adds up to something relatively large. Notice that if I substitute 0. (the real) with 0 (the integer or rational), then the result is exactly like expected. Do any of you know why this happens and how I could avoid it, other than working with *only* rational numbers? Thank you!
- Follow-Ups:
- Re: erroneous result when adding reals
- From: Sseziwa Mukasa <mukasa@jeol.com>
- Re: erroneous result when adding reals
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: erroneous result when adding reals