# Plotting function containing NIntegrate: trace the values of convergence problems

Suppose you are plotting a function

Plot[f[x],{x,0,10}]

Where

f[x]=NIntegrate[g[x,t],{t,Tmin,Tmax}].

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.

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

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

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

plot