# Mathematica saying “NIntegrate failed to converge to prescribed accuracy ” for this integral ploting

Plot[y/(32*\[Pi]^4)*12^2*(2.09*10^-11)^2*100^2/(192 \[Pi])
NIntegrate[((x - 2*100^2)^2 - 4*100^4)/Sqrt[x]
Sqrt[(x - 4*100^2) (x - 4*100^2)/
x^2] (x^2 - 4*100^2*x +
12*100^4)/((x - 5^2)^2 ((x - 100^2)^2 + (4.15*10^-3*100)^2))
BesselK[1, Sqrt[x]/y], {x, 4*10^4, \[Infinity]}], {y, 8*10^-3,
10^10}, PlotRange -> {{8*10^-3, 10^10}, {8*10^-44, 10^16}}]


When i am trying to plot it , Mathematica gives an empty plot and shows

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {5.57963*10^7}. NIntegrate obtained 2.5480460753667857*^6 and 21453.774416999564 for the integral and error estimates.


## 2 Answers

Writing:

a = 2 100^2;
b = 415 10^-3;

f[x_] := ((x - a)^2 - a^2)/Sqrt[x] (x - 2 a)/x (x^2 - 2 a x + 3 a^2)/((x - 25)^2 ((x - a/2)^2 + b^2))
g[x_, y_] := 131043/128 10^-22/Pi^5 f[x] y BesselK[1, Sqrt[x]/y]
h[y_] := NIntegrate[g[x, y], {x, 2 a, Infinity}, Method -> "Trapezoidal"]

Plot[h[y], {y, 8 10^-3, 10^10}]


I get:

which is what is desired.

Wanting to specialize everything in the case of several plots to compare in the same plan, writing:

listA = {2, 10, 50} 100^2;
listB = {415, 420, 425} 10^-3;
listC = {Blue, Green, Red};
listD = {{"first"}, {"second"}, {"third"}};

f[x_] := ((x - a)^2 - a^2)/Sqrt[x] (x - 2 a)/x (x^2 - 2 a x + 3 a^2)/((x - 25)^2 ((x - a/2)^2 + b^2))
g[x_, y_] := 131043/128 10^-22/Pi^5 f[x] y BesselK[1, Sqrt[x]/y]
h[y_] := NIntegrate[g[x, y], {x, 2 a, Infinity}, Method -> "Trapezoidal"]

plots = Table[a = listA[[i]];
b = listB[[i]];
Plot[h[y], {y, 8 10^-3, 10^10},
PlotStyle -> listC[[i]],
PlotLegends -> listD[[i]]],
{i, 3}];

Show[plots, AxesLabel -> {"x", "y"}]


I get:

that seems to make her look good!

• Is there any way to write a general code for such functions and by varying different parameters, i can get different desired results? – Dark Knight45 Jun 25 '19 at 3:46
• @DarkKnight45: in principle, yes, it is possible, but you should be more specific so that you can respond precisely. – TeM Jun 25 '19 at 5:46
• Like here in your written code a,b contains some variable squared and i have to plot 5 more such plots in the same graph with changing these variable – Dark Knight45 Jun 25 '19 at 6:35
• @DarkKnight45: I changed the answer, see if it meets your needs. – TeM Jun 25 '19 at 12:09
• Ok i will follow accordingly – Dark Knight45 Jun 25 '19 at 12:37

With adapted PrecisionGoal and PlotRange your code works without warning:

Plot[y/(32*\[Pi]^4)*12^2*(2.09*10^-11)^2*100^2/(192 \[Pi]) NIntegrate[((x - 2*100^2)^2 - 4*100^4)/Sqrt[x]Sqrt[(x - 4*100^2) (x - 4*100^2)/x^2] (x^2 - 4*100^2*x +12*100^4)/((x - 5^2)^2 ((x - 100^2)^2 + (4.15*10^-3*100)^2)) BesselK[1, Sqrt[x]/y], {x, 4*10^4, \[Infinity]}
,PrecisionGoal->5 ], {y, 8*10^-3,10^10}, PlotRange -> All]


• Is there any way to write a general code for such functions and by varying different parameters i can get different desired results? – Dark Knight45 Jun 24 '19 at 19:13
• @DarkKnight45 It appears that the question is morphing. What have you tried thus far for coding a parametrized version? – Daniel Lichtblau Jun 25 '19 at 14:04