Suppose you are plotting a function




and when plotting, the warning message

NIntegrate::ncvbNIntegrate failed to converge to prescribed accuracy after N
recursive bisections in t near {t} = c. NIntegrate obtained *number*
and *other number* for the integral and error estimates

is printed (typically once). Unfortunately, it doesn't seem obvious for which value(s) of x the problem appears.

Is there a way to tell on which range of x your plot is reliable?

In case of a DensityPlot it can even be harder to estimate the validity domain.

It would be great if there were for example a possibility for Mesh->All to draw the badly convergent points in a different color.


I'm not sure how you want to present the result, but you can cull the errors for each integration with IntegrationMonitor.

f[x_Real] := Block[{f`error, f`int},
   f`int = NIntegrate[BesselJ[2, x t], {t, 0, 40000},
     IntegrationMonitor -> ((f`error = Total[Map[#1@"Error" &, #1]]) &)];
   (*Sow[{x,f`error},"error"];*)    (* absolute error *)
   Sow[{x, Abs[f`error/(10^-6*f`int)]}, "scalederror"];   (* for  PrecisionGoal -> 6  *)

{plot, {se}} = Reap[Plot[f[t], {t, 0, 1}], "scalederror"];
se = Sort[se];

    DeleteCases[se, {_, Indeterminate}], {All, 2}],
   VertexColors -> ColorData["RedGreenSplit"] /@ UnitStep[1 - se[[All, 2]]]]
  }, AspectRatio -> 0.6, Axes -> True]

Mathematica graphics


Mathematica graphics


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.