繁体   English   中英

python中的scipy quad集成问题

[英]Issue with scipy quad integration in python

我是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)中的修正贝塞尔函数,该函数返回Nan值,但其他方程结果Fk2却为0。一段时间以来,我遇到了以下错误:

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。 非常感谢任何帮助,我在这里迷失了。

您的s2值相当大(15000.0)。 因此,当您在s2处评估贝塞尔函数时 ,您将得到零:

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

因此,函数t1始终返回零,使积分为零。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM