我试着用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
正如@ForceBru所说,使用SymPy函数:
相关问题 更多 >
编程相关推荐