# Quick questions about a document example for Components and Data Structures

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.

1. Creating an NDSolveStateData object, which includes the info needed to solve the equation:

 state = First[NDSolveProcessEquations[{x''[t] + (1 + 4 UnitStep[Sin[t]]) x[t] == 0, x[0] == 1, x'[0] == 0}, x, t, Method -> "ExplicitRungeKutta"]]

(* NDSolveStateData[<0.>] *)

2. Integrating the equation up to t = 10 Pi with the time interval specified by a list of intermediate times

 NDSolveIterate[state, Pi Range[10]]

3. Generating the current solution and associated derivatives in the forward directon

 sol = NDSolveProcessSolutions[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 NDSolveIterate 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 NDSolveProcessSolutions 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 NDSolveIterate[state, list_of_times]?

(2) I can understand that NDSolveProcessSolutions 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?

• I get a different last element, which is the discrete variable used to code the discontinuities arising from UnitStep: i.stack.imgur.com/fo1ux.png -- What version are you using? – Michael E2 Aug 22 '20 at 14:06
• Possibly by "intermediate times to stop," they mean this: Table[ NDSolveIterate[state, t0]; NDSolveProcessSolutions[state, "Forward"] , {t0, Pi Range[10]}] – Michael E2 Aug 22 '20 at 14:07
• @MichaelE2 Reply to 1st comment: I am using v9 and got the same thing as in the documentation. Did you think that the last element will be problem-dependent? Reply to 2nd comment: Just as I guessed, it allows us to obtain the intermediate solution. Can we save them with Table[ NDSolveIterate[state, t0]; NDSolveProcessSolutions[state, "Forward"] ; sol >> ToString[t0].m", {t0, Pi Range[10]}]? – user55777 Aug 22 '20 at 15:00
• Event handling was changed in version 10. They added WhenEvent on the user-facing side and I expect they changed the internal handling as well (for instance, what we get for sol). What I know about NDSolve 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. – Michael E2 Aug 22 '20 at 15:30
• @MichaelE2 Thank you for the explanation. – user55777 Aug 23 '20 at 1:49