-1

I have a problem using the function integrate.nquad.

I get this error: "TypeError: can't multiply sequence by non-int of type 'float'"

I understand that I have a string somewhere, but I can´t find it exactly

If someone would please help me with this I would be very grateful. Thanks in advance.

from scipy import integrate
import numpy as np
def f(D,S):
        Ka = 0.08
        C = 500
        R = 0.05
    return np.exp(-Ka*C*((R-S)*np.cos(D) *(np.sin(D))**2))
Io = 3.58*10**16
R = 0.05
I = (Io/(R*np.pi)) * integrate.nquad(f,[[0, R],[0, np.pi]])
Vineet Jain
  • 1,515
  • 4
  • 21
  • 31

1 Answers1

0
from scipy import integrate
import numpy as np
def f(D,S):
    Ka = 0.08
    C = 500
    R = 0.05
    return np.exp(-Ka*C*((R-S)*np.cos(D) *(np.sin(D))**2))
Io = 3.58*10**16
R = 0.05
I = (Io/(R*np.pi)) * integrate.nquad(f,[[0, R],[0, np.pi]])[0]

According to the documentation, nquad returns 2 (or 3, if the right parameter is set) items: the result (integrated value), the maximum of the estimates of the absolute error in the various integration results, and optionally a dict with additional information.

You're attempting to multiple a 2-tuple returned by nquad by (Io/(R*np.pi)): that's causing your error.

Take the first element of the returned tuple (note the [0] as the last bit of code above) and you'll have what you want.