# Is there a reason behind strange noise appearing for some coefficients of polynomial in NIntegrate?

It occurs for instance here:

b = -1; c = 1; d = -1;
Plot[NIntegrate[1/(a*x^3 + b*x^2 + c*x + d), {x, 0, 10}], {a, 0, 2}]


but not with these values:

  b = 1; c = 1; d = 1;


The phenomenon seems to appear with negative coefficients.

• If you use RootSum[] instead, things are much nicer: With[{b = -1, c = 1, d = -1}, Plot[RootSum[d + c #1 + b #1^2 + a #1^3 &, (Log[10 - #1] - Log[-#1])/(c + 2 b #1 + 3 a #1^2) &], {a, 0, 2}, PlotRange -> All]] Commented Dec 25, 2020 at 14:38
• Your integrand has a pole in the integration interval. This makes the numeric integral error prone. For the second set of parameters, the poles are outside the integration interval. Commented Dec 25, 2020 at 14:57

A generation ago Plot used to let all (or many) messages escape, so that if you plotted a function like 1/x, you wouldn't be surprised at a divide-by-zero error message. You got used to typing Plot[1/x, {x, -1, 1}] // Quiet. Nowadays, Plot is very aggressive at suppressing message, too aggressive in this case, imo.

Modifying @Szabolcs's code, here's a way to see that Plot is hiding thousands of nonconvergence NIntegrate::ncvb errors from you:

b = -1; c = 1; d = -1;
messages = {};
clearMessages[] := messages = {};
collectMessages[m_] :=
messages = {messages, m /. Hold[_[mm_, ___], _] :> HoldForm[mm]};
InternalHandlerBlock[
{"Message", collectMessages},
Plot[NIntegrate[1/(a*x^3 + b*x^2 + c*x + d), {x, 0, 10}], {a, 0, 2}]
];
Tally[Flatten@messages]


Here's another way I might do it, since I can never remember the handler stuff:

obj[a_?NumericQ] := Module[{res},
Check[
res = NIntegrate[1/(a*x^3 + b*x^2 + c*x + d), {x, 0, 10}],
++foo; res,
NIntegrate::ncvb]
];
foo = 0;
Plot[obj[a], {a, 0, 2}]
foo
(*  plot omitted *)
(*  2986  *)


I ignore the slow convergence NIntegrate::slwcon warnings, which are hints why the integral does not converge. But I already know why it does not converge.

P.S. There is a method option "SuppressMessages", but it is undocumented and seems not to apply. It takes True or False for values, but it makes no difference here:

Plot[NIntegrate[1/(a*x^3 + b*x^2 + c*x + d), {x, 0, 10}], {a, 0, 2},
MaxRecursion -> 0, (* for speed *)
Method -> {"SuppressMessages" -> False}]


Try it with Method -> {"SuppressMessages" -> None} and you will be told to use True or False`. So it is an option that is checked.