2
$\begingroup$

I am trying to solve an ODE with NDSolve using the "ExplicitRungeKutta" method. I need to know exactly which time steps NDSolve chooses, i.e., which points in the interval $[tmin, tmax]$ it chooses when it implements the Runge-Kutta method before the interpolation is made). What should I do?

$\endgroup$
  • 2
    $\begingroup$ See NDSolveStateData, in particular the section NDSolve`StateData Properties; also see NDSolveExplicitRungeKutta; other methods can be found in NDSolveOverview. $\endgroup$ – Michael E2 May 29 '14 at 12:12
  • 2
    $\begingroup$ NDSolveUtilities can be used for analyzing the solution after the solution has been constructed. $\endgroup$ – Michael E2 May 29 '14 at 13:13
  • 2
    $\begingroup$ quick and dirty way: ClearAll[g]; g[x_?NumericQ] := (Sow[x]; Cos[x]); ListPlot@Last@ Last@Reap[NDSolve[{y'[x] == y[x] g[x], y[0] == 1}, y, {x, 0, 30}, Method -> "ExplicitRungeKutta"]] $\endgroup$ – acl May 29 '14 at 23:09
2
$\begingroup$

To take this off the unanswered list:

The steps are the abscissae stored in the interpolating function returned by NDSolve:

ysol = First@
   NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 10}, 
    Method -> "ExplicitRungeKutta"];

steps = y["Coordinates"] /. ysol // First
(*
  {0., 0.120351, 0.527517, 0.921285, 1.33461, 1.85473, 2.27071, 
   2.75617, 3.20612, 3.69883, 4.24451, 4.86677, 5.51721, 6.0665, 
   6.59295, 7.1106, 7.57393, 8.07059, 8.6011, 9.25316, 9.62658, 10.}
*)
$\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.