你好,我对 python 很陌生,我正在尝试解决一组方程。我正在尝试将四重积分的结果乘以 float ,我的代码是:
from __future__ import division
import scipy.special as sp
from scipy import integrate
import math
Tb = 7.2
Tc = 9.3
t = Tb / Tc
n = 2*10**-6
L = 50*10**-6
W = 80*10**-9
a = 3*10**-2
s1 = W/ (2*n)
y1 = (L+(W/2)) / (2*n)
x0 = 0.015
r0 = 4*x0
s2 = (r0 / n)/1000000
print s2
y0 = (x0 / n)/1000000
def t1(t):
return t**-1*sp.kv(0, s2)
def t2(t):
return t**-1*sp.iv(0, s2)
print t2
Fk2 = (math.pi**-2) * integrate.quad(t1, s1, s2)
FI2 = (math.pi**-2) * integrate.quad(t2, s1, s2)
print Fk2 , FI2
我不断收到错误
25 print t2
---> 26 Fk2 = (math.pi**-2) * integrate.quad(t1, s1, s2)
27 FI2 = (math.pi**-2) * integrate.quad(t2, s1, s2)
28 print Fk2 , FI2
TypeError: can't multiply sequence by non-int of type 'float'
我很不确定要做什么,我尝试用 lambda 函数替换 def t1(t)
但同样没有任何作用。非常感谢任何帮助,并提前感谢您。
最佳答案
由于您是初学者,所以我首先要说的是,每当您遇到不理解的错误时,请将该行分成多个单独的步骤,以便您可以准确地找出错误所指的内容,例如这个:
temp = integrate.quad(t1, s1, s2)
print "temp:", temp
Fk2 = (math.pi**-2) * temp
然后你可以看到错误是 temp 是一个元组,并且没有定义如何将元组乘以 float 。
Fk2 = (math.pi**-2) * np.array(temp[:2])
你可以在 the documentation 中看到每个术语所指的含义。
关于python - Python Quad 积分乘以 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26171505/