[英]TypeError: can't convert expression to float with Sympy
I'm trying to use sympy but am having trouble with its Symbol Objects. 我正在尝试使用sympy,但其Symbol Objects遇到了麻烦。
import sympy as sy
from scipy import special as sp
def derivativeBMax2(s):
x = sy.symbols('x', real=True)
B0 = 1
H = 1
alpha = 2.4048
B_azimuthal = B0 * H * sp.jv(1, alpha * sy.sqrt((float(x) ** 2) + (s ** 2)))
sp.jv from its documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.jv.html 来自其文档的sp.jv: https ://docs.scipy.org/doc/scipy/reference/produced/scipy.special.jv.html
requires a float for its second argument and when I convert x into a float it raises 它的第二个参数需要一个浮点数,当我将x转换为一个浮点数时,它会引发
TypeError: can't convert expression to float
I want to eventually differentiate B_azimuthal with sympy's diff() 我想最终用sympy的diff()区分B_azimuthal
How can I make x both a symbol and also a float for scipy's jv function? 如何使x既是符号又是scipy的jv函数的浮点数?
If scipy requires a float there is nothing you can do (other than replace the Symbol x with a float). 如果scipy需要浮点数,则您无能为力(用浮点数代替Symbol x除外)。 If you want to work with it symbollically, why not just use SymPy's besselj
function in sympy/functions/special/bessel.py
. 如果要象征性地使用它,为什么不直接在sympy/functions/special/bessel.py
使用SymPy的besselj
函数。 The docstring of that function gives examples of using symbolic arguments and does a differentiation, too. 该函数的文档字符串提供了使用符号参数的示例,并且也进行了区分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.