0
return sp.integrate.quad(int_jean, R, 10)/R
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
1/R
似乎是導致錯誤,但我看不出爲什麼。它應該被一個浮動分開。我繪製了被積函數,它看起來沒問題。在Python中進行看似正常的劃分時出現類型錯誤
import matplotlib.pyplot as plt
import scipy as sp
import numpy as np
def nu(r):
return 1/r
def int_jean(r):
return nu(r)/r**2
def rms(R):
return sp.sqrt(3 * sp.integrate.quad(int_jean, R, 10)/R
print(rms(5))
t1 = np.arange(0.1, 10.0, 0.01)
m = list(map(int_jean, t1))
print(m)
plt.plot(t1, m)
plt.show()
的類型錯誤是相當明確的有關問題...'quad'是返回一個元組 – donkopotamus