1
$\begingroup$

The following piece of code

SetDirectory[NotebookDirectory[]];   

f[r_] := Tanh[100*(r - 3/10)] + Tanh[100*(4/10 - r)]
Plot[f[x], {x, 0, 1}] 

s = NDSolve[{y'[x] == D[f[x], x], 
   y[1] == f[1]}, {y}, {x, -1/1000000000, 1}, 
  Method -> "ExplicitRungeKutta", WorkingPrecision -> 100, 
  AccuracyGoal -> 30, PrecisionGoal -> 30, InterpolationOrder -> All, 
  MaxSteps -> 10^6, StartingStepSize -> 10^-8]

data = Table[
   Flatten@{N[x, 40], N[y[x] /. s, 40], 
     N[f[x] - (y[x] /. s), 40]}, {x, N[0/10, 100], N[10/10, 100], 
    N[1/100, 100]}];   
Export["known_solution_test.txt", data, "TSV"];  

reproduces numerically the known solution f[r_] within $30$ decimal digits, as seen in known_solution_test.txt.

However the following warning pops-up

N::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating {-Tanh[60]+Tanh[70]}.

Is it something I should take into consideration? Or how can I fix it?

$\endgroup$
1
  • 3
    $\begingroup$ Have you looked up $MaxExtreaPrecision? There's some advice in the docs. $\endgroup$ – Michael E2 Dec 4 '19 at 15:10
2
$\begingroup$

As mentioned in the documentation for $MaxExtraPrecision, you can temporarily increase its value for your calculation:

Block[{$MaxExtraPrecision = 100},
  s = <yourcode for s>;
  data = <your code for data>;
]

The warning is not triggered then.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy