I want to solve an expression in SymPy
JavaScript
x
2
1
lg(10/b^3) = lg10-3lg5 = 1-3lgb (lgb = 5 => b = 10^5) = 1-15 = -14
2
But then I try to code it like this
JavaScript
1
4
1
b = 10**5
2
expression = log(10/(b**3), 10)
3
expression
4
The result isn’t correct.
Advertisement
Answer
You’ve got the result with ten digits, and not the decimal logarithm. Documentation says,
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.
You can divide result by log(10) or define your own function, like this:
JavaScript
1
5
1
class log10(Function):
2
@classmethod
3
def eval(cls, x):
4
return log(x)/log(10)
5
Anyway, to get the desired result, you should use either simplify(expr).evalf()
or N(expr)
:
JavaScript
1
6
1
>>> expr = log(10/b**3)/log(10)
2
>>> expr
3
-32.2361913019166/log(10)
4
>>> N(expr)
5
-14.0000000000000
6