MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Lost Values after For[ ] loop

  • To: mathgroup at
  • Subject: [mg65540] Re: [mg65487] Lost Values after For[ ] loop
  • From: "Tony Harker" <a.harker at>
  • Date: Thu, 6 Apr 2006 06:53:19 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Let's be clear just what is strange.  You are dealing with floating point
numbers, and they aren't stored exactly. If you wrap a FullForm round the
output in your second notebook you'll see that what's actually stored is,
for example, xt[90.47999999999999] rather than xt[90.48].  The iterator in
the Table command, however, looks for xt[90.48]. So what you are actually
seeing is a subtle difference between what is done in your For loop and what
is done in Table's iterator. If you used the same constructions to generate
and to collect your results, they'd match.


Dr A.H. Harker
Department of Physics and Astronomy
University College London
Gower Street

]->-----Original Message-----
]->From: rondeau at [mailto:rondeau at] 
To: mathgroup at
]->Subject: [mg65540] [mg65487] Lost Values after For[ ] loop
]->Here is a problem I find completely baffling.
]->After several days of frustration, I have pin-pointed the 
]->failures of my program to the the issue:
]->I run a For[] loop with an iterator I call "t1".
]->The loop is simply a successive evaluation of an NDSolve[] 
]->with subsequent interpolation of the result. The way I have 
]->it right now, this simplified problem always evaluates the 
]->same ODE numerically.
]->The problem, is that depending on how small or large the 
]->step for t1 is (i.e. how many times I ask the ODE to be 
]->evaluated in the loop), I may or may not be able to recover 
]->all solutions for the different executions of NDSolve.
]->In the first notebook below, everything is fine. The 
]->increment in t1 is 0.25. I get all the solutions I want, 
]->either by asking for a Print[] of particular values of the 
]->interpolated function (e.g. 3.2 in the example
]->below) for any t1 I choose or by creating a table of values.
]->However, in the second notebook below, alI I change is 
]->change the increment (from 0.25 to 0.24). Now, I can no 
]->longer recover all of my results. If I do a Print[], I see 
]->that the values are there, but when I call the values 
]->directly, I only get the first few of them. For most values 
]->of t1, I cannot get the evaluation of the interpolated 
]->function at all and therefore cannot re-use in later 
]->computations. How can it be that the increment results in a 
]->change of behavior and how can it be that I can Print[] the 
]->values, but cannot list them and use them all?
]->I know that this is not a machine or a memory problem. With 
]->a step of 0.25, I can ask for any number of interations on 
]->the NDSolve I want and I can always recover the solutions. I 
]->also get the same results on another machine.
]->This is very bizarre to me. Any help would be greatly appreciated.

  • Prev by Date: Re: Re: simplify a trig expression
  • Next by Date: Re: another problem with Infinite Products
  • Previous by thread: Re: Lost Values after For[ ] loop
  • Next by thread: Complex number after NIntegrate