python中的scipy quad集成问题

时间:2014-10-03 16:45:35

标签: python numpy scipy integration quad

我对python很陌生,所以我希望我的措辞有意义。我目前正在尝试建模一组方程式,这些方程式要求积分乘积乘以浮点数。我仅从集成输出中获得了Nan输出,我不知道为什么我的代码如下:

from __future__ import division
import matplotlib.pylab as plt
import numpy as np
import scipy.special as sp
import scipy as sci
from scipy import integrate
import math
from sympy.functions import coth
Tc = 9.25
Tb = 7.2
t = Tb / Tc
Temperature = []
Temp1=[]
Temp0=[]
D=[]
d = []
D1=[]
d1 = []
n = 2*10**-6
L = 100*10**-9
W = 80*10**-9
a = 3*10**-2
s1 = W/ (2*n)
y1 = (L+(W/2)) / (2*n)
x0 = 0.015
r0 = 2*x0
s2 = r0 / n
y0 = (x0 / n)/1000000
print x0, y0, y1
A = ((W/n)**2) *(sp.kv(0, s1)+(math.pi / 2)*sp.kv(1,s1)*coth(y1))
B = ((W/n)**2) *(sp.iv(0, s1)+(math.pi / 2)*sp.iv(1,s1)*coth(y1))
print A, B
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, full_output=False)[0]
FI2 =(math.pi**-2) * integrate.quad(t2, s1, s2, full_output=False)[0]
print Fk2 , #FI2
r1 = 0.0
while r1 < y1:
    #C0 = sp.kv(0,s2)*(1 + (A*FI2)-(B*Fk2))/A
    #print C0
    #D_ = 1 - B*Fk2 - A*Fk2*sp.iv(1, s1) / sp.kv(1, 1)
    #print D_
    r1 += 0.0001
    j = -1*r1
    D.append(r1)
    d.append(j)
    #T = Tb + (Tc - Tb) * (sp.kv(0,s1) + (math.pi /2)* sp.kv(1, s1)*coth(r1))*(1- D_ * math.cosh(y1)) * (C0*A)
    #Temp0.append(T)
    #print Temp0, r1

主要罪魁祸首似乎是方程FI2 sp.iv(t2,s1)中修改后的bessel函数返回Nan值,但另一个方程结果Fk2给出0.一段时间我得到以下错误:< / p>

IntegrationWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated. warnings.warn(msg, IntegrationWarning) 

但已停止,现在我只得到0.0和Nan。我真的很感激任何帮助,我在这里很失落。

1 个答案:

答案 0 :(得分:1)

你对s2的价值相当大(15000.0)。因此,当您在s2评估Bessel Function时,您得到零:

>>> sp.kv(0, 15000.0)
0.0

所以你的函数t1总是返回零,使整数为零。