Function integration returns error "only length-1 arrays can be converted to Python scalars"

Asked

Viewed 41 times

1

I’m trying to integrate a function into a certain range that shows the particle flux in a zero-angle (theta) direction as a function of the E energy of the particles. I’ve tried a lot of different ways, and I’ve gotten different mistakes, but this is the one that always sticks at the end. My knowledge of Python is limited and I don’t understand how to get the full.

My job right now is like this:

from numpy import radians, cos, arange
from matplotlib.pyplot import plot, yscale, xscale, xlabel, ylabel
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)
     #flux = a*b*c*1**4
     return ((a*b*c*1**4))
     #print(flux)

     """
     plot(flux)
     yscale('log')
     xscale('log')
     xlabel('E')
     ylabel('Fluxo')
     """

#integral(0)

A, err= quad(integral, 500, 1000)

If I remove the self from the function argument I get the error:

"integral() takes 0 positional Arguments but 1 was Given"

I don’t know how to fix.

Does anyone know the solution to this case?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.