[Date Index]
[Thread Index]
[Author Index]
Lost Values after For[ ] loop
*To*: mathgroup at smc.vnet.net
*Subject*: [mg65487] Lost Values after For[ ] loop
*From*: rondeau at uvic.ca
*Date*: Wed, 5 Apr 2006 06:55:26 -0400 (EDT)
*Organization*: University of Victoria
*Sender*: owner-wri-mathgroup at wolfram.com
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.
D.R.
FIRST NOTEBOOK
IN>
For[t1=90,t1<95,t1=t1+0.25,
sol1[t1]=NDSolve[{x'[t]?0.001*x[t],x[0]?1},{x},{t,0,10}];
xt[t1]=Interpolation[Table[Flatten[{t,x[t]/.sol1[t1]}],{t,0,10}]];
xt[t1][s];]
IN>
For[t1=90,t1<95,t1=t1+0.25,Print[{t1,xt[t1][3.2]}]];
OUT>
{90,1.00321}
{90.25,1.00321}
{90.5,1.00321}
{90.75,1.00321}
{91.,1.00321}
{91.25,1.00321}
{91.5,1.00321}
{91.75,1.00321}
{92.,1.00321}
{92.25,1.00321}
{92.5,1.00321}
{92.75,1.00321}
{93.,1.00321}
{93.25,1.00321}
{93.5,1.00321}
IN>
Table[{t1,xt[t1][3.2]},{t1,90,94.999,0.25}];
OUT>
{{90,1.00321},{90.25,1.00321},{90.5,1.00321},{90.75,1.00321},{91.,1.00321},{91.25,1.00321},{91.5,1.00321},{91.75,1.00321},{92.,1.00321},{92.25,1.00321},{92.5,1.00321},{92.75,1.00321},{93.,1.00321},{93.25,1.00321},{93.5,1.00321},{93.75,1.00321},{94.,1.00321},{94.25,1.00321},{94.5,1.00321},{94.75,1.00321}}
SECOND NOTEBOOK
IN>
For[t1=90,t1<95,t1=t1+0.24,
sol1[t1]=NDSolve[{x'[t]?0.001*x[t],x[0]?1},{x},{t,0,10}];
xt[t1]=Interpolation[Table[Flatten[{t,x[t]/.sol1[t1]}],{t,0,10}]];
xt[t1][s];]
IN>
For[t1=90,t1<95,t1=t1+0.24,Print[{t1,xt[t1][3.2]}]];{90,1.00321}
OUT>
{90.24,1.00321}
{90.48,1.00321}
{90.72,1.00321}
{90.96,1.00321}
{91.2,1.00321}
{91.44,1.00321}
{91.68,1.00321}
{91.92,1.00321}
{92.16,1.00321}
{92.4,1.00321}
{92.64,1.00321}
{92.88,1.00321}
{93.12,1.00321}
{93.36,1.00321}
{93.6,1.00321}
{93.84,1.00321}
{94.08,1.00321}
{94.32,1.00321}
{94.56,1.00321}
{94.8,1.00321}
IN>
Table[{t1,xt[t1][3.2]},{t1,90,94.999,0.24}]
OUT>
{{90,1.00321},{90.24,1.00321},{90.48,1.00321},{90.72,1.00321},{90.96,1.00321},{91.2,xt[91.2][3.2]},{91.44,xt[91.44][3.2]},{91.68,xt[91.68][3.2]},{91.92,xt[91.92][3.2]},{92.16,xt[92.16][3.2]},{92.4,xt[92.4][3.2]},{92.64,xt[92.64][3.2]},{92.88,xt[92.88][3.2]},{93.12,xt[93.12][3.2]},{93.36,xt[93.36][3.2]},{93.6,xt[93.6][3.2]},{93.84,xt[93.84][3.2]},{94.08,xt[94.08][3.2]},{94.32,xt[94.32][3.2]},{94.56,xt[94.56][3.2]},{94.8,xt[94.8][3.2]}}
Prev by Date:
**Re: simplify a trig expression**
Next by Date:
**Re: simplify a trig expression**
Previous by thread:
**Re: Transformstion to canonical form**
Next by thread:
**Re: Lost Values after For[ ] loop**
| |