# How to discard NDSolveStateData intermediate data

I'd like to prepare the equations with NDSolve'ProcessEquations and then doing repetitive NDSolve'Iterate for the steps.

I need only variable values at each step, not the final InterpolatingFunction and the computation may run indefinitely.

Is it possible to discard state data for processed steps?

• NDSolveProcessEquations[{y’[x]==y[x],y[0]==1, y, {x, 1, 2}] will save only the solution between x==1 and x==2, I think. – Michael E2 Jan 14 at 11:29
• @MichaelE2 I think this comment should be an answer. – Pavel Perikov Jan 14 at 11:53
• related – andre314 Jan 14 at 15:26

I thought this was described in some NDSolve tutorial, but I can't find it. It is mentioned in Only final result from NDSolve, which @andre314 linked in a comment.

The call

NDSolveProcessEquations[{y’[x] == y[x], y[a] == 1}, y, {x, b, c}]


with an initial condition at x == a and interval b <= x <= c will save only the solution between x == b and x == c. The end points b and c may be the same, in which case only the solution at x == b will be saved.

Since I couldn't find documentation, I tested it empirically (see below). With a call of the form

NDSolveProcessEquations[ivp, y, {x, x1, x1}]


the user is responsible for storing solution data after each call to NDSolveIterate[]. The data will be discarded with the next call that advances the integration time front.

Appendix: Empirical evidence

First call: save the whole solution.

Quit[]

Block[{n = 30},
char = Times @@ Table[(m^2 + k), {k, 1, n}]; {state} =
NDSolveProcessEquations[{CoefficientList[char, m] .
Table[Derivative[k][y][x], {k, 0, 2 n}] == 0,
Table[Derivative[k][y][0] == 1, {k, 0, 2 n - 1}]}, y, {x, 0, 300},
MaxSteps -> 10^5]
]
NDSolveIterate[state, 0.01] (* initialize the iteration loop *)
mu = MaxMemoryUsed[];
NDSolveIterate[state, 300]
MaxMemoryUsed[] - mu

(*  13558848  *)


Second call: save only the endpoint.

Quit[]

Block[{n = 30},
char = Times @@ Table[(m^2 + k), {k, 1, n}]; {state} =
NDSolveProcessEquations[{CoefficientList[char, m] .
Table[Derivative[k][y][x], {k, 0, 2 n}] == 0,
Table[Derivative[k][y][0] == 1, {k, 0, 2 n - 1}]},
y, {x, 300, 300}, MaxSteps -> 10^5]
]
NDSolveIterate[state, 0.01](* initialize the iteration loop *)
mu = MaxMemoryUsed[];
NDSolveIterate[state, 300]
MaxMemoryUsed[] - mu

(*  12432  *)