4

I am running this python code to derive the equation. ​R(x)=50 * ln(5x + 1)

derivative

i tried numpy.log and 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()

I am expecting to get the equation after derivative but i am getting the error

---------------------------------------------------------------------------
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
Community
  • 1
  • 1

1 Answers1

4

Don't mix the math with sympy. Use log from 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)
Omri Attiya
  • 3,917
  • 3
  • 19
  • 35