4

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?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Pavel Perikov
  • 1,345
  • 6
  • 14

1 Answers1

7

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

NDSolve`ProcessEquations[{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

NDSolve`ProcessEquations[ivp, y, {x, x1, x1}]

the user is responsible for storing solution data after each call to NDSolve`Iterate[]. 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 -&gt; 10^5] ] NDSolveIterate[state, 0.01] (* initialize the iteration loop *) mu = MaxMemoryUsed[]; NDSolve`Iterate[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 -&gt; 10^5] ] NDSolveIterate[state, 0.01](* initialize the iteration loop *) mu = MaxMemoryUsed[]; NDSolve`Iterate[state, 300] MaxMemoryUsed[] - mu

(*  12432  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747