我正在运行此python代码以导出方程式。 R(x)= 50 * ln(5x +1)
我尝试了numpy.log和math.log
from sympy import Symbol, Derivative
import numpy as np
import math
x= Symbol('x')
function = 50*(math.log(5*x+1))
deriv= Derivative(function, x)
deriv.doit()
我期望得到微分后的方程,但是我得到了错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-107-e41161e3f329> in <module>()
5 x= Symbol('x')
6
----> 7 function = 50*(math.log(5*x+1))
8
9 deriv= Derivative(function, x)
~/anaconda3/lib/python3.7/site-packages/sympy/core/expr.py in __float__(self)
254 if result.is_number and result.as_real_imag()[1]:
255 raise TypeError("can't convert complex to float")
--> 256 raise TypeError("can't convert expression to float")
257
258 def __complex__(self):
TypeError: can't convert expression to float
答案 0 :(得分:2)
请勿将math
与sympy
混合使用。使用log
中的sympy
:
import sympy as sp
x= sp.Symbol('x')
y = 50*(sp.log(5*x+1))
deriv= sp.Derivative(y, x)
deriv.doit()
print(deriv.doit()) #250/(5*x + 1)