Message Boards Message Boards

Plot the DifferenceOrder with AdamsBM method in NDSolve?

Posted 6 years ago

In the notebook attached, I solve an ordinary differential equations with the AdamsBM method discussed here, and plot the error of the method as a function of t.

How may I plot the DifferenceOrder of the method as a function of t?

Attachments:
POSTED BY: Joao Porto
3 Replies

You're welcome. :)

POSTED BY: Michael Rogers
Posted 6 years ago

Thank you.

POSTED BY: Joao Porto

Add this before the last line of of the definition AdamsBM[data_]["Step"[rhs_, t_, h_, y_, yp_]]:

Sow[{t + hnew, knew}, "Adams order"];

Then

{sol, {orders}} = Reap[
   NDSolve[{x''[t] + x[t] == Sin[3 t], x[0] == 1, x'[0] == 0}, 
    x, {t, 0, 2 \[Pi]}, Method -> AdamsBM, WorkingPrecision -> 32],
   "Adams order"];

To plot:

Listplot[orders]

Or skip the modification and just do:

sol = NDSolve[{x''[t] + x[t] == Sin[3 t], x[0] == 1, x'[0] == 0}, 
    x, {t, 0, 2 \[Pi]}, Method -> AdamsBM, WorkingPrecision -> 32, InterpolationOrder -> All];

And plot:

solIF = x /. First@sol;
Transpose@{solIF[[3, 1]], (Length /@ solIF[[4]]) - 1} // ListPlot

enter image description here

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract