InterpolatingFunction resulting from a numerical algorithm like NDSolve would have the same node distribution as the algorithm. And it seems to be true.
{s, steps} =
Reap[NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1},
y, {x, 0, .05}, StepMonitor :> Sow[{x, y[x]}][[1]]]];
Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"];
coords = First[InterpolatingFunctionCoordinates[y /. s[[1]]]]
steps[[1, All, 1]]
The both
coords and steps give the same values:
{5.13196*10^-6, 0.0000102639, 0.00339028, 0.00677029, 0.0101503,
0.0151503, 0.0201503, 0.0251503, 0.0301503, 0.0351503, 0.0401503,
0.0450752, 0.05}
However, the
Mesh option of Plot shows another set of points (green):
stpl = ListPlot[steps,
PlotStyle -> Directive[PointSize[Large], Red]];
Show[
Plot[Evaluate[y[x] /. s], {x, 0, .016}, Mesh -> All,
MeshStyle -> Directive[PointSize[Medium], Green]], stpl]
And it seems that the
Mesh directive has no connection with the structure of InterpolatingFunction. Let's make larger Plot and cut of a part which corresponds to the previous figure:
stpl = ListPlot[steps,
PlotStyle -> Directive[PointSize[Large], Red]];
Show[
Plot[Evaluate[y[x] /. s], {x, 0, .05}, Mesh -> All,
MeshStyle -> Directive[PointSize[Large], Green]], stpl,
PlotRange -> {{0, 0.016}, {1, 1.0085}}]


Žádné komentáře:
Okomentovat