简体   繁体   English

TypeError:无法将表达式转换为使用Sympy浮动

[英]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.

相关问题 sympy TypeError:无法将表达式转换为浮点数 - sympy TypeError: can't convert expression to float Sympy:TypeError:无法将表达式转换为浮点型 - Sympy: TypeError: can't convert expression to float Python:sympy TypeError:无法将表达式转换为浮点数 - Python : sympy TypeError: can't convert expression to float TypeError:无法将表达式转换为浮点数 - 定积分 sympy - TypeError: can't convert expression to float - definite integral sympy Sympy“无法将表达式转换为浮点数”错误 - “Can't convert expression to float” error with sympy 无法将表达式转换为浮点数 - 使用 sympy - Can't convert expression to float - using sympy 非线性方程求解Sympy Python用于液压 - 需要解决TypeError(“无法将表达式转换为浮点数”) - Non-linear equation solving Sympy Python for hydraulics - Need resolve TypeError(“can't convert expression to float”) TypeError:无法将表达式转换为浮点型 - TypeError: can't convert expression to float 类型错误:无法将表达式转换为浮点数,使用符号 x,多项式插值 - TypeError: can't convert expression to float, with symbolic x, polynomial interpolation sympy的plot_parametric说TypeError:无法将复数转换为浮点数 - sympy's plot_parametric says TypeError: can't convert complex to float
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM