I should probably change what I say up front:
The full error message, perhaps surprisingly, is saying there is nothing to worry about, and no fix is needed.
This is the opposite of most people's reactions to error messages, including mine, especially when the message leads with the word "failed."
The point is to think about this part of the error message:
NIntegrate
obtained -1.24910*^-16
and 4.588053980254483*^-13
for the integral and error estimates.
That means NIntegrate
calculated the integral to be in the interval
{-4.586804880254483`*^-13, 4.589303080254483`*^-13}
Now, is that a good enough answer?
Probably, it is, unless you believe (for other reasons, say, based on what the value is supposed to represent) that the integral is nonzero and smaller than 10^-13
. Probably you don't need to do anything; just accept the answer. On the other hand, if an uncertainty of 4.6*10^-13
is unacceptable, then none of the methods discussed below fix that; they just hide the problem.
The OP's method is better than the NDSolve
method, which lies well outside this interval and corresponds to its AccuracyGoal
of about 8
.
The OP's method is better than the NIntegrate
answer obtained by integrating 1 + integrand
and subtracting 2 Pi
for somewhat technical reasons: The default precision goal is about 6
, which means that the error in the value the integral is bounded by 2 Pi 10*^-6
, which is much greater than 4.6*10^-13
. Further, while the value of the integral in this method (minus 2 Pi
) lies inside the interval, it is much larger than the value of the OP's integral.
The OP's method is better than lowering AccuracyGoal
. The setting AccuracyGoal -> a
means roughly that if the absolute error is less than 10^-a
, NIntegrate
will accept the result. By lowering AccuracyGoal
, you are actually telling NIntegrate
to accept a worse result. A good reason to do this is given in one of the answers @MarcoB linked: A lower setting speeds up NIntegrate
when the integral is (nearly) zero, because it is easier to compute a less accurate result.
There is nothing very wrong in these other methods. Unless you need more than 8 decimal places of accuracy, which almost certainly is not the case here, they are fine but no better than the OP's method. The error message in this case in fact indicates how good the answer is. In other cases, it might indicate how bad the answer could be.