Round-off error?
- To: mathgroup at smc.vnet.net
- Subject: [mg131931] Round-off error?
- From: D Yong <darrylyong at gmail.com>
- Date: Wed, 30 Oct 2013 23:47:15 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
Hi everyone, The following lines of code are stumping me. ClearAll[y] dt = 0.15; Do[y[i*dt] = "hi there", {i, 0, 20}] Table[{i, y[(i + 1)*dt], y[i*dt + dt]}, {i, 0, 19}] Here is the output: 0 hi there hi there 1 hi there hi there 2 hi there hi there 3 hi there hi there 4 hi there hi there 5 hi there y(0.9) 6 hi there y(1.05) 7 hi there hi there 8 hi there hi there 9 hi there hi there 10 hi there hi there 11 hi there hi there 12 hi there y(1.95) 13 hi there hi there 14 hi there hi there 15 hi there hi there 16 hi there hi there 17 hi there hi there 18 hi there y(2.85) 19 hi there hi there It seems that y[i*dt+dt] does not match y[(i+1)*dt], perhaps due to numerical round-off? If you switch to dt=15/100, the problem goes away. You might also try different values for dt to see what happens. If it is numerical round-off, then why does this evaluate to true? 6*.15 == 5*.15 + .15 True Thanks in advance for your input! Darryl