3

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?

CDJB
  • 14,043
  • 5
  • 29
  • 55
vic
  • 35
  • 1
  • 1
  • 6

1 Answers1

6

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

CDJB
  • 14,043
  • 5
  • 29
  • 55
  • 2
    I wanted to add something for people who may be confused as to what this operation is called. This operation is called the change of base. That is, log_3(x) = ln(x)/ln(3) where log_3(x) is the log base 3 of x. – Gabe Morris Jan 25 '22 at 02:53