0

I want to take the derivative of the following function y=(np.log(x))/(1+x), if I am using sympy, it gives me the following error

    from sympy import *
    y1=Derivative((np.log(x))/(1+x), x)
    print y1

sequence too large; cannot be greater than 32

Sanjeev
  • 209
  • 1
  • 3
  • 8
  • 1
    Is that all of your code? Should you not introduce some symbolic variables to sympy (instead on passing undefined python variables like ```x```)? – sascha Jan 13 '17 at 03:25
  • @Sanjeev Although it may seem inconvenient, try to [avoid `from ... import *`](http://stackoverflow.com/questions/2386714/why-is-import-bad). – MB-F Jan 13 '17 at 08:05
  • Thanks Sascha and Kazemakase... – Sanjeev Jan 13 '17 at 16:22

1 Answers1

1

Do it like this:

>>> from sympy import *
>>> var('x')
x
>>> y1 = diff(log(x)/(1+x))
>>> y1
-log(x)/(x + 1)**2 + 1/(x*(x + 1))
  • As Sanjeev mentioned in a comment you need to define variables in one way or another.
  • np.log in your code would be a function that accepts a numerical value and returns a numerical value; sympy needs to see a function names that it knows in formal terms, such as log
  • In this context, you need to use sympy's diff function, rather than Derivative.
Bill Bell
  • 21,021
  • 5
  • 43
  • 58
  • Thanks Bell...Today I went through the complete documentation of sympy from the start and found this thing....thanks a lot!!! and thanks for explaining the np.log thing – Sanjeev Jan 13 '17 at 16:13
  • Sanjeev, you're most welcome. I hope you enjoy using sympy as much as I do. – Bill Bell Jan 13 '17 at 16:15