I want to run an integral for different values of "e" and "m" and put the results in a list.
m =[0.14, 0.14, 0.14, 1.30, 4.50]
e = [2/3, -1/3, -1/3, 2/3, -1/3]
def f(z, r):
return ((e)**2)*(alpha_elm*Nc/2*np.pi**2)*(4)*(Q2)*(z**2)*((1-z)**2)*((scipy.special.k0(r*(z*(1-z)*Q2 (m**2))))**2)
integrate.nquad(f, [[0, 1],[0, np.inf]])
how can i do that?
CodePudding user response:
You can define a partially applied version of your function where you set the values for e and m. Then iterate over their ranges of values and compute the specific results:
from functools import partial
def f(m, e, z, r):
return ((e)**2)*(alpha_elm*Nc/2*np.pi**2)*(4)*(Q2)*(z**2)*((1-z)**2)*((scipy.special.k0(r*(z*(1-z)*Q2 (m**2))))**2)
results = []
for mm, ee in zip(m, e):
partial_f = partial(f, mm, ee)
result = integrate.nquad(partial_f, [[0, 1], [0, np.inf]])
results.append(result)
I would however strongly suggest to reformat and break down the overly complex definition of your function f
.