同感分化

2024-06-08 04:53:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用SymPy来区分下列等式:

log(n)**k

import math, sympy
from sympy.abc import x, y, n, k
print(sympy.diff(math.pow(math.log(n, 2), k), n))

但是我从SymPy那里得到了can't convert expression to float错误。 我做错什么了?你知道吗

runfile('C:/Users/towis/.spyder-py3/temp.py', wdir='C:/Users/towis/.spyder-py3')
Traceback (most recent call last):

  File "<ipython-input-19-3728a7ec31a4>", line 1, in <module>
    runfile('C:/Users/towis/.spyder-py3/temp.py', wdir='C:/Users/towis/.spyder-py3')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/towis/.spyder-py3/temp.py", line 6, in <module>
    print(sympy.diff(math.pow(math.log(n,2), k), n))

  File "C:\ProgramData\Anaconda3\lib\site-packages\sympy\core\expr.py", line 226, in __float__
    raise TypeError("can't convert expression to float")

TypeError: can't convert expression to float

Tags: inpylogconvertlinepy3sitemath

热门问题