# Gauss Kronrod Rule of numerical integration

I tried to make the following numerical integration accurately.

\[Xi]1 = 0.999998 - 0.0053014 I;\[Eta]1 = -1.1196366*^8 + 5.403396*^6 I;e0 = 2*10^9;s1 = -0.0009433 + 2.733469*^-7 I;al = 5.6198;
p1 = {{8011.093134 + 329.781879 I}, {1902.0266450 +
14.797328 I}, {-1045.822299 + 25.025568 I}, {699.714569 -
29.590978 I}, {-515.009091 + 29.013683 I}, {-515.009091 +
29.013683 I}, {401.664020 - 27.428940 I}, {-325.798670 +
25.727027 I}, {271.880762 - 24.130404 I}, {-231.830775 +
22.687591 I}};
w1[x_] := 1/\[Xi]1 + (2*\[Eta]1 - 2)/\[Pi]*1/e0*
NIntegrate[
Sum[(-1)^(n - 1)*p1[[n, 1]]*Cos[u*x]/(1 + s1*Sqrt[u^2 - al^2])*u*
Sin[u/2]/(u^2 - 4*(n - 1)^2*\[Pi]^2), {n, 1, 10}], {u, 0,
al, \[Infinity]}, MaxRecursion -> 100000,
Method -> "GaussKronrodRule"];tab1 = Table[{x, Re[#], Im[#]} &[w1[x]], {x, 5/100, 10, 5/100}];
d1 = ListLinePlot[tab1[[1 ;; -1, {1, 2}]], Frame -> True, BaseStyle -> {FontFamily -> "Times", FontSize -> 16}, FrameLabel -> {"x", "y"}, InterpolationOrder -> 4, PlotRange -> {{0.5, 10}, {-300, 300}}]


I tried many Integrate Rules based on similar problems I found here. Only the GaussKronrodRule gives me quick output but with these errors:

NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 400 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained 5028.05 +10712.9 I and 22.916945212347706 for the integral and error estimates. Is this can be acceptable result? is there any way to improve it?

• So you've tried Method -> "LevinRule" and got errors? What version are you using? The NIntegrate::eincr error casts doubt on the result; I would seek some confirmation, at least at a few spots scattered over 1/20 <= x <= 10. It's possible that at most points you get no error. – Michael E2 Feb 24 '18 at 23:50
• Thank you Michael E2. I am using 11.1.0.0 Mathematica version. Yes I have tried LevinRule method and I got this error – Mariam Tohari Feb 25 '18 at 4:32
• Thank you Michael E2. I am using 11.1.0.0 Mathematica version. Yes I have tried LevinRule method and I got better result specially for x > 8 during longer time compared to "Gauss Kronrod Rule" with these errors ..(1) NIntegrate::mtdfb: Numerical integration with LevinRule failed. The integration continues with Method -> GaussKronrodRule. (2) The global error of the strategy GlobalAdaptive has increased more than 400 .... – Mariam Tohari Feb 25 '18 at 4:42

Factor out the factors of the sum that do not depend on n. For some reason Factor (nor NIntegrate) can separate them out. This causes the system for the Levin rule to be large and very slow, sometimes so slow that a time constraint is reached. With them factored out manually, the integration is moderately fast. The are a few slow convergence warnings, but no errors indicating the convergence goals were not met.

w1[x_] :=
1/ξ1 + (2*η1 - 2)/π*1/e0*
NIntegrate[
Sin[u/2] Cos[u*x] u / (1 + s1*Sqrt[u^2 - al^2]) *
Sum[(-1)^(n - 1)*p1[[n, 1]]/(u^2 - 4*(n - 1)^2*π^2), {n, 1, 10}],
{u, 0, al, ∞},  (* I don't think the  al  is needed *)
MaxRecursion -> 20, Method -> "LevinRule"];

tab1 = Monitor[
Table[{x, Re[#], Im[#]} &[w1[x]], {x, 5/100, 10, 5/100}],
x]; // AbsoluteTiming
(*  {35.227, Null}  *)

d1 = ListLinePlot[tab1[[1 ;; -1, {1, 2}]], Frame -> True,
BaseStyle -> {FontFamily -> "Times", FontSize -> 16},
FrameLabel -> {"x", "y"}, InterpolationOrder -> 4,
PlotRange -> {{0.5, 10}, {-300, 300}}] Change the NIntegrate method to

Method -> {"LevinRule", Method -> {"GaussKronrodRule", "Points" -> 21}}


saves 5-6 sec. in computing the Table.

The sampling in the plot above is not sufficiently dense, except to give some idea of the magnitude of the oscillation. For example (takes 50+ sec.):

Plot[Re@w1[u], {u, 2, 2.1}, MaxRecursion -> 3]
` 