希望能从我的代码中得到一些指导,我对python还很陌生,在代码中修改bessel函数k0时遇到了困难。实际代码分为两部分
1)第一节使用sympy求解t并返回t=0时x0的值。你知道吗
2)第二部分使用这个值x0来求解不同x值的t
就在第二步,我遇到了困难scipy.特殊.k0函数似乎不适用于指定的x0值,我不知道为什么
from __future__ import division
import sympy as sy
from sympy import besselk, log, nsolve
import math
import numpy as np
import scipy.special as sp
Tc = 9.2
Tb = 5.2
tb = Tb / Tc
print 'Value of tb is:'+' '+ str(tb)
L = 100*10**-9
W = 100*10**-9
n = 3*10**-6
r1 = W / 2
print 'value of r1 is:'+' '+ str(r1)
x1 = r1 /n
print 'value of x1 is'+ ' '+ str(x1)
S = math.sqrt(3 / (1+ tb + tb**2))
print 'value of S is:'+' ' + str(S)
B = (math.pi / 2)*(1+(L/W))
print 'value of B is:'+' ' + str(B)
E = [x /10 for x in range (1, 2, 1)]
x0 = sy.symbols('x0')
i = (S*x0)*(1-tb**3)*besselk(0, x0) / 3*(log(x0/x1)+B) * besselk(0, S*x0)
t = - i*( (log(x0/x1)*B)**2 - (log(x0/x1)+B)**2 )
X0 = nsolve(t, E)
G = sp.k0(X0)
print 'value of x0 is:' +' '+ str(X0)
当我运行代码时,它会导致以下错误
TypeError: ufunc 'k0' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
如有任何帮助,我们将不胜感激。你知道吗
X0
不是常规浮点值;它是mpmath
中的mpf
类型(作为sympy的一部分包含)。scipy.special.k0
不知道那是什么。更改此项:对此:
相关问题 更多 >
编程相关推荐