英文:
Sympy returns log instead of ln
问题
Sympy返回:
1/(x*log(3))
Sympy应该返回:
1/(x*ln(3))
为什么Sympy返回了log函数而不是自然对数函数?
英文:
I have this equation:
import sympy as sp
x = sp.Symbol(‘x’, real = True)
fx = sp.log(x,3)
sp.diff(fx, x)
Sympy returns:
1/(x*log(3))
Sympy should return:
1/(x*ln(3))
Why is Sympy returning the log function rather than the natural log function?
答案1
得分: 6
>#注意:
在SymPy中,与Python和大多数编程语言一样,log表示自然对数,也称为ln。SymPy自动提供了别名ln = log,以防您忘记这一点。
>>> sp.ln(x)
log(x)
所以您发布的代码实际上是正确的。
sp.log(x,3)
等效于log(x)/log(3)
,其导数是1/(x*log(3))
,在SymPy中等效于1/(x*ln(3))
。
英文:
From here:
>#Note:
In SymPy, as in Python and most programming languages, log is the natural logarithm, also known as ln. SymPy automatically provides an alias ln = log in case you forget this.
>>> sp.ln(x)
log(x)
So the code you have posted is in fact, correct.
sp.log(x,3)
is equivalent to log(x)/log(3)
, and the derivative of this is 1/(x*log(3))
which in Sympy is equivalent to 1/(x*ln(3))
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论