R = 0.05; l = 0.1;
q0 = 200;
alpha = 17.64;
lambda1 = 67.9;
def integral2(x, z, r):
s = 0;
if z > 0:
s = 1
elif z == 0:
s = 0.5
else:
s = 0
B = ((lambda1*math.tan(x) - alpha) * math.exp(2 * math.tan(x) * l)) - ((lambda1*math.tan(x) + alpha) * math.exp((-2) * math.tan(x) * l))
BZ = ((math.cosh(z+l) * ((lambda1 * math.tan(x) * math.cosh(math.tan(x)*l)) - (alpha * math.sinh(math.tan(x)*l)))) / B) - ((math.sinh(math.tan(x)*z) * s) / math.tan(x))
result = ((mpmath.j0(r * math.tan(x)) * mpmath.j1(R * math.tan(x))) / (math.pow(math.cos(x),2) * math.pow(math.tan(x),2))) * BZ
return result
r = 0
resArr = [];
rArr = [];
while r < 1:
r += 0.01
r = math.ceil(r*100)/100;
res, _ = scipy.integrate.quad(integral2, 0, (np.pi / 2) - 0.02741184711388415, args=(l/2, r))
resArr.append(res*R*q0/lambda1)
rArr.append(r)
Hello! I am trying to understand why I get "The integral is probably divergent, or slowly convergent." in this case. Can anybody help me?
Thanks!
After adding the required imports, we can plot your integrand:
At
x=0, there is a singularity.If we zoom in a bit, we can see there appears to be another singularity around
x=0.85.Even if they are integrable, they are going to be challenging for numerical integrators. This is why you're getting the warning:
quadknows its having trouble, and it's letting you know that the results may not be reliable. Forscipy.integrate.quadto have any hope of handling the mid-interval singularity, you'd need to use thepointsargument to tell it where the singularity occurs. I decided to go a different route to investigate further, though.Some quadrature schemes can handle some singularities at the endpoints of the integration interval.
mpmath's implementation of the Tanh-Sinh rule is one such scheme, and since you were already usingmpmath(albeit unnecessarily -scipy.specialhasj0andj1), I figured I'd see ifmpmath.quadcould handle the singularity atx=0.The result appears to double when the working precision is doubled, so I don't think it is converging to a correct answer. Your integral might not be finite.