我想使用 Simpy 绘制 Hankel 函数的二阶导数。在Mathematica中,它很简单:
D[HankelH2[1,z],z]
这可以通过使用属性进行分析,
二阶和一阶汉克尔函数的一阶导数分别等于二阶零阶和二阶的两个汉克尔函数之差,所有这些都除以二。
但我想学习如何使用 Sympy 直接推导它。到目前为止,我已经尝试过:
from scipy.special import hankel2
import sympy as sp
x = sp.Symbol('x')
dh2 = sp.diff(lambda x: hankel2(1,x),x)
错误消息对我来说似乎难以辨认:
SympifyError Traceback (last last call last) in () 1 import sympy as sp 2 x = sp.Symbol('x') ----> 3 dh2 = sp.diff(lambda x: hankel2(1,x),x )
/usr/lib/python2.7/dist-packages/sympy/core/function.pyc in diff(f, *symbols, **kwargs) 1639 """ 1640 kwargs.setdefault('evaluate', True) -> 1641返回导数(f, *symbols, **kwargs) 1642 1643
/usr/lib/python2.7/dist-packages/sympy/core/function.pyc in new (cls, expr, *variables, **assumptions) 985 def new (cls, expr, *variables, **assumptions): 986 --> 987 expr = sympify(expr) 988 989 # 没有变量,我们区分所有的自由符号
/usr/lib/python2.7/dist-packages/sympy/core/sympify.pyc in sympify(a, locals, convert_xor, strict,rational, evaluate) 313 expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate) 314 except (TokenError, SyntaxError) as exc: --> 315 raise SympifyError('could not parse %r' % a, exc) 316 317 return expr
SympifyError: Sympify of expression 'could not parse u' at 0x7fdf3eca9e60>'' 失败,因为引发了异常:SyntaxError: invalid syntax (, line 1)
任何线索我的错误在哪里?
提前致谢。