0
$\begingroup$

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 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.>] *)
    
  2. Integrating the equation up to t = 10 Pi with the time interval specified by a list of intermediate times

     NDSolve`Iterate[state, Pi Range[10]]
    
  3. 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?

$\endgroup$
5
  • $\begingroup$ 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? $\endgroup$ – Michael E2 Aug 22 '20 at 14:06
  • $\begingroup$ Possibly by "intermediate times to stop," they mean this: Table[ NDSolve`Iterate[state, t0]; NDSolve`ProcessSolutions[state, "Forward"] , {t0, Pi Range[10]}] $\endgroup$ – Michael E2 Aug 22 '20 at 14:07
  • $\begingroup$ @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]}]? $\endgroup$ – user55777 Aug 22 '20 at 15:00
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Aug 22 '20 at 15:30
  • $\begingroup$ @MichaelE2 Thank you for the explanation. $\endgroup$ – user55777 Aug 23 '20 at 1:49

Your Answer

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

Browse other questions tagged or ask your own question.