Message Boards Message Boards

Plot the DifferenceOrder with AdamsBM method in NDSolve?

GROUPS:

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
Answer
4 months ago

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
Answer
4 months ago

Thank you.

POSTED BY: Joao Porto
Answer
4 months ago

You're welcome. :)

POSTED BY: Michael Rogers
Answer
3 months ago

Group Abstract Group Abstract