4
$\begingroup$

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?

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

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} = 
  NDSolve`ProcessEquations[{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]
 ]
NDSolve`Iterate[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} = 
  NDSolve`ProcessEquations[{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]
 ]
NDSolve`Iterate[state, 0.01](* initialize the iteration loop *)
mu = MaxMemoryUsed[];
NDSolve`Iterate[state, 300]
MaxMemoryUsed[] - mu
(*  12432  *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.