5

I have eqs about the NDSolve, I know this code given the solving automatically.

How can I find out what method is used behind the scenes? How can I gauge the reliability level, find how many iterations have been used, the order of method. How can I estimate the error?

I found hints on this site, but I still do not fully understand.

It is impossible to say NDSolve has automatically solution for publishing paper?

I used this code related to my system:

r = 0.431201; β = 2.99 *10^-6; σ = 0.7; δ = 0.57;
{m = 0.3, η = 0.1, μ = 0.1, ρ = 0.3};


S = {N1'[t] == r N1[t] (1 - β N1[t]) - η  N1[t] I1[t],
     I1'[t] == σ + (ρ  N1[t]  I1[t])/( m + N1[t]) - δ I1[t] - μ  N1[t] I1[t]};

c = {N1[0] == 1, I1[0] == 1.22};

Select[Flatten[
  Trace[
    NDSolve[{S, c}, {N1, I1}, {t, 0, 30}], 
    TraceInternal -> True]], 
  !FreeQ[#, Method | NDSolve`MethodData] &]

but I don't understand the output.

xzczd
  • 65,995
  • 9
  • 163
  • 468
sana alharbi
  • 105
  • 6
  • 2
    Partial duplicate: https://mathematica.stackexchange.com/questions/145/how-to-find-out-which-method-mathematica-selected – Michael E2 Mar 24 '19 at 01:17
  • This tutorial shows how to monitor several things: https://reference.wolfram.com/language/tutorial/NDSolvePlugIns.html#41467666 – Michael E2 Mar 24 '19 at 01:19
  • @MichaelE2 I used this technic but I don't understand – sana alharbi Mar 24 '19 at 01:19
  • 1
    Another partial duplicate: https://mathematica.stackexchange.com/questions/102704/inspecting-step-size-and-order-of-tt-ndsolve – Michael E2 Mar 24 '19 at 01:37
  • What other input are you supplying? What is S, c, N1, I1? – mjw Mar 24 '19 at 01:44
  • 1
    You say you don't understand some technique or other, nor the output of your Trace[] command. But the first is a very general statement about things already explained and the second is about a command that no one else can reproduce – Michael E2 Mar 24 '19 at 01:44
  • @mjw this is related to my system the out put is – sana alharbi Mar 24 '19 at 02:05
  • 2
    "It is impossible to say NDSolve has automatically solution for publishing paper. " Simply saying "I've used NDSolve function of software Mathematica" is enough in many cases, AFAIK. – xzczd Mar 24 '19 at 03:39
  • I know that and the reviewer asks me about the method, Some reliability level, iterations @xzczd – sana alharbi Mar 24 '19 at 03:49
  • 4
    Well, if the reviewer insists on such stuff, given that your system isn't that difficult, a possible workaround at this point is to choose a primary method like classical RK4 to solve the problem. The way to choose classical RK4 in NDSolve can be found in tutorial/NDSolveExplicitRungeKutta#1456351317, then you just need to set Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 4, "Coefficients" -> ClassicalRungeKuttaCoefficients}, StartingStepSize -> 1/20000, MaxSteps -> Infinity in NDSolve. The solving process is slower but gives the same result as given by default. – xzczd Mar 24 '19 at 03:59
  • 2
    This is indeed a general issue using Mathematica for reproducible science. Every built-in function should have an option to output the exact method being chosen. – Chris K Mar 24 '19 at 08:22
  • @xzczed Thanks for you comment – sana alharbi Mar 24 '19 at 09:14

1 Answers1

6

Comment

In response to your question, you already got very valuable comments. I will just try to comment on

How can I estimate the error?

For this I am going to plot residual error at steps and time, which will show the reliability and accuracy of NDSolve,

r = 0.431201; \[Beta] = 2.99*10^-6; \[Sigma] = 0.7; \[Delta] = 0.57;
m = 0.3; \[Eta] = 0.1; \[Mu] = 0.1; \[Rho] = 0.3;   

ode = {N1'[t] == r N1[t] (1 - \[Beta] N1[t]) - \[Eta] N1[t] I1[t], 
   I1'[t] == \[Sigma] + (\[Rho] N1[t] I1[t])/(m + N1[t]) - \[Delta] I1[t] - \[Mu] N1[t] I1[t]};

bcs = {N1[0] == 1, I1[0] == 1.22};

residuals = ode /. Equal -> Subtract;

{s} = NDSolve[{ode, bcs}, {N1, I1}, {t, 20}, InterpolationOrder -> All];

N1["Coordinates"] /. s;

residuals /. t -> N1["Coordinates"] /. s;

ListPlot[Abs[Flatten /@ (residuals /. t -> N1["Coordinates"] /. s)], Frame -> True]

enter image description here

With[{data = {Table[{t, Abs@residuals[[1]]} /. s, {t, N1["Coordinates"] /. s // Flatten}]}}, 
 ListLogPlot[data, Frame -> True, PlotRange -> All]]

enter image description here

Note: I adopted the above from this website but unable to find the link.

zhk
  • 11,939
  • 1
  • 22
  • 38
  • Thank you so much @zhk but how can defend the axes for both figures? the first as x represented steps and y residual error. the second one x represents the t time and y residual error. sorry if my question is trivial but it is first time to see the code – sana alharbi Mar 24 '19 at 09:13
  • For all can we use StartingStepSize->0.125 with MaxStep->Infinity in NDsolve and ExplicitRungeKutta. What is the meaning of these commends, ( it is lead to fixed steps or variable step? so, what is the mean of Infinity in Mathematica it is unbounded, i think not? – sana alharbi Jul 18 '20 at 07:14