Any help to double integrate this function probably in python:
Becaue when I run the following code it gives an error:
IntegrationWarning: The integral is probably divergent, or slowly convergent.
I try to integrate a function f(k,t1)
then plot it versus the variable k
(in the python file $tau$ is $t_1$)
But the function dominator may contain some singularity which gives divergences meanwhile the integration, so I appreciate any help to solve the error of divergence and run the code.
Here is the code that I use , now it freezes after giving errors:
import numpy as np
import scipy.special
from scipy import integrate
from scipy.special import kn
import matplotlib.pyplot as plt
import math
import time, sys
k=3;a=0.1;nab=10**-9;n=0.94;kz= 0.002;
# Define the function to be integrated
def f(m,t1,k):
return (-(50*t1**2*(-16*(16 + 20*t1 + 6*t1**2 + 4*t1**3 + 3*t1**4) + (1 + t1)**2*(448 + 1568*t1 + 2400*t1**2 + 1920*t1**3 + 864*t1**4 + 240*t1**5 + 72*t1**6 + 42*t1**7 + 18*t1**8 + 3*t1**9)*math.exp((4*(1 + t1))/(2 + t1))) + m*(1 + t1)*(-128 + 1536*t1**2*math.exp((4*(1 + t1))/(2 + t1)) + 2112*t1**4*math.exp((4*(1 + t1))/(2 + t1)) + 1008*t1**5*math.exp((4*(1 + t1))/(2 + t1)) + 312*t1**6*math.exp((4*(1 + t1))/(2 + t1)) + 114*t1**7*math.exp((4*(1 + t1))/(2 + t1)) + 60*t1**8*math.exp((4*(1 + t1))/(2 + t1)) + 21*t1**9*math.exp((4*(1 + t1))/(2 + t1)) + 3*t1**10*math.exp((4*(1 + t1))/(2 + t1)) + 64*t1*(-1 + 6*math.exp((4*(1 + t1))/(2 + t1))) + 32*t1**3*(-1 + 78*math.exp((4*(1 + t1))/(2 + t1)))))/(0.01+4.*(1 + t1)*(2 + t1)*(-48 - 96*t1 + 8*(-3 + 2*m**2)*t1**2 + 8*(3 + 2*m**2)*t1**3 + (6 + 4*m**2)*t1**4 + 6*t1**5 + 3*t1**6))) * (50 * t1**2 +k)
X = np.arange(1,10,0.1)
def F(x):
res = np.zeros_like(x)
for i,val in enumerate(x):
y,err = integrate.dblquad(f, 0.1, 2, lambda x: 0.1, lambda x: 2, args=(val,))
res[i]= y
return res
plt.plot(X,F(X))
plt.title("P(k), H=2.5")
plt.xlabel("k")
plt.ylabel("P")
plt.savefig('P(k).png')