2 replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
source | link
1
source | link

Ways to get information about an ODE solution sol = NDSolve[..., {x,..}, {t, a, b}]:

  • Steps:
    • x["Grid"] /. sol
    • x["Coordinates"] /. sol
    • Reap[NDSolve[..., StepMonitor :> Sow[t]]
  • Method:
    • Reap[NDSolve[..., MethodMonitor :> Sow[NDSolve`Self]]
    • Trace[NDSolve[...], NDSolve`InitializeMethod[__], TraceInternal -> True]
  • Evaluations:
    • Reap[NDSolve[..., EvaluationMonitor :> Sow[t]]

Example (OP's but with a shorter interval of integration):

Block[{nstep = 0, neval = 0},
  {sol2, {steps2, methods2, eval2}} = 
   Reap[NDSolve[{x1'[t] == x2[t], 
      x2'[t] == -5 x2[t] - 44 y1[t] - 0.5 x1[t] y1[t] + Sin[5 t], 
      y1'[t] == y2[t], 
      y2'[t] == -3 y2[t] - 2 x2[t] + x1[t] y1[t]^2 + Cos[5 t], 
      x1[0] == 0.1, x2[0] == 0.02, y1[0] == 0.2, y2[0] == 0.01},
     {x1, x2, y1, y2}, {t, 0.1},
     Method -> Fehlberg45,
     StepMonitor :> (Sow[{++nstep, t}, "Step"];),
     "MethodMonitor" :> (Sow[NDSolve`Self, "Method"];),
     EvaluationMonitor :> (Sow[{++neval, nstep, t}, "Evaluation"];), 
     MaxStepFraction -> 1],    (* allow longer steps because of short interval *)
    {"Step", "Method", "Evaluation"}]
  ];

A presentations of the steps & evaluation times:

Grid[
 Join[
  {{"Step", "Evaluations", SpanFromLeft}},
  MapIndexed[Join[#2, #1] &,
   SplitBy[First@eval2, #[[2]] &][[All, All, 3]]]
  ],
 Alignment -> {Left, Automatic}]

Mathematica graphics

methods2[[1, 1]] // Short

Mathematica graphics

x1["Grid"] /. sol2
(*{{{0.},{0.0115275},{0.0280347},{0.0448688},{0.0620601},{0.0795363}, {0.0897682},{0.1}}}*)

Note that the default method "LSODA" does not use "MethodMonitor". Use Trace[] to see the NDSolve`LSODA method object it uses.

References: