Sympy返回log而不是ln。

huangapple go评论95阅读模式
英文:

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)).

huangapple
  • 本文由 发表于 2020年1月3日 16:18:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/59575202.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定