Hello,
I have the following problem with understanding whether an unwanted
precision loss occurs in my calculations, and I would appreciate some
help. I solve some ODEs using NDSolve, and since the calculations
are very expensive, they are split into several runs. In one run
the calculations are stopped when the available time or memory limits
are approached. The value of the independent variable th, corresponding
to this situation is stored as thmax. This value then becomes the end of the integration interval. The code is:
wprec=50;
ivpsol=NDSolve[
{ivp, WhenEvent[(TimeUsed[] > maxctime || MemoryInUse[] > maxmemory) && th>0, thmax=th;"StopIntegration","LocationMethod"->"StepBegin"]}
,soltable,{th,th0,thmax},WorkingPrecision->wprec,PrecisionGoal->wprec/2,
MaxSteps->Infinity,InterpolationOrder->All
,StepMonitor:>Print[{th,N[Subscript[psix,1][th],20]}]
];
Please note that the working precision is 50, so that one expects
that 50 digits of thmax should be available. Indeed, if I now
export thmax to a file, according to:
Export[file,Join[{thmax},endpsivalues,endphivalues],"List"];
I can see that 50 digits of thmax are in the file (this is
the first of the following numbers stored:
4.2381878739099146976942608527708919906248917152657e6
0.0048230113561383041835207418808668133329086696535244
0.0048249194434038473837547000974380792009777840867437
0.0048330661478961510678031863401831999702176813779798
etc.
I also print the value into another file, according to:
Write[strm,OutputForm["# thmax = "],CForm[thmax]];
with the result:
# thmax = 4.2381878739099146976942608527708919906248917152657e6
However, in a next run of my calculations, the file “file” is imported
to provide starting values for further integration, and the former variable
thmax becomes the initial value th0 of the independent variable,
according to the code:
initvalues=SetPrecision[Import[file,"List"],Infinity];
th0=First[initvalues];
When I now print the th0, according to the code:
Write[strm,OutputForm["# th0 = "],CForm[th0]];
I get the printout:
# th0 = 4.238187873909915e6
As it seems, only 16 digits are printed, which seems to indicate some
precision loss, despite the fact that SetPrecision[…,Infinity] was used
on input.
Is this really a precision loss, and how can one avoid it?
Lesław