NDSolve
can be broken into several basic steps for advanced usage according to Components and Data Structures. In the documentation, a simple example is given as follows.
Creating an
NDSolve`StateData
object, which includes the info needed to solve the equation:state = First[NDSolve`ProcessEquations[{x''[t] + (1 + 4 UnitStep[Sin[t]]) x[t] == 0, x[0] == 1, x'[0] == 0}, x, t, Method -> "ExplicitRungeKutta"]] (* NDSolve`StateData[<0.>] *)
Integrating the equation up to
t = 10 Pi
with the time interval specified by a list of intermediate timesNDSolve`Iterate[state, Pi Range[10]]
Generating the current solution and associated derivatives in the forward directon
sol = NDSolve`ProcessSolutions[state, "Forward"] (* {x[31.4159] -> 0.843755, Derivative[1][x][31.4159] -> -1.20016, (x'')[31.4159] -> -0.843755, (x'')[31.4159] -> (x'')[31.4159] -> -1} *)
I have two questions with regard to the step 2 and 3, respectively.
(1) The document states that NDSolve`Iterate
allows you to specify intermediate times at which to stop. This can be useful to avoid discontinuities. It sounds great but I don't understand what does it mean by at the intermediate times to stop. Does it mean that by specifying intermediate times we can use NDSolve`ProcessSolutions
to save all the intermediate solutions otherwise we only have a solution for the final time? Can anyone give an example to demonstrate how to avoid discontinuities in solving a differential equation with NDSolve`Iterate[state, list_of_times]
?
(2) I can understand that NDSolve`ProcessSolutions
gives the solution and associated derivatives in the step 3, however, I do not understand what is the last element in its output list, i.e., (x'')[31.4159] -> (x'')[31.4159] -> -1
?
UnitStep
: i.stack.imgur.com/fo1ux.png -- What version are you using? $\endgroup$ – Michael E2 Aug 22 '20 at 14:06Table[ NDSolve`Iterate[state, t0]; NDSolve`ProcessSolutions[state, "Forward"] , {t0, Pi Range[10]}]
$\endgroup$ – Michael E2 Aug 22 '20 at 14:07Table[ NDSolve
Iterate[state, t0]; NDSolveProcessSolutions[state, "Forward"] ; sol >> ToString[t0].m", {t0, Pi Range[10]}]
? $\endgroup$ – user55777 Aug 22 '20 at 15:00WhenEvent
on the user-facing side and I expect they changed the internal handling as well (for instance, what we get forsol
). What I know aboutNDSolve
and discontinuity/event handling I learned post V10. I have no way of finding out what's different in V9. What you got,(x'')[31.4159] -> (x'')[31.4159] -> -1
, can probably be interpreted as(x'')[31.4159] -> eventsignature
that indicates at(x'')[31.4159]
the direction the event (which is an equation) is being crossed (decreasing/increasing). That's just a guess, though. $\endgroup$ – Michael E2 Aug 22 '20 at 15:30