-1
區分我試圖用SymPy區分下列公式:在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
請給整個錯誤消息。 –
當然,在這裏你去 編輯:編輯問題 – ToTom
你很可能從Python的'數學'模塊得到這個錯誤,因爲'math.pow'&'math.log'計算冪函數的相應浮點數_values_和對數。他們需要_floats_作爲輸入。 – ForceBru