I'm trying to integrate a function into a given range that shows the flow of particles in a zero-angle (theta) direction as a function of the energy E of the particles. I've tried several ways and got different errors but there are two that persist at the end. My knowledge of Python is limited, I try to learn new ways of doing stuff as I need them but I've been around this function for days with no success.
My function at the moment looks like this:
from numpy import radians, cos, arange
from scipy.integrate import quad
def integral(self):
theta=0
E = arange(1, 5000, 1)
costh = cos(radians(theta))
a = 18 / (E * costh + 145)
b = (E + 2.7 / costh)**-2.7
c = (E + 5) / (E + 5 / costh)
return a*b*c*1**4
A = quad(integral, 500, 1000)
Applying "quad" to the function like this returns:
TypeError: only length-1 arrays can be converted to Python scalars
If I don't put "self" as argument in the funtion, it returns:
TypeError: integral() takes 0 positional arguments but 1 was given
Has someone an idea on how to bypass this?