pythondifferentiation

How can I calculate the analytical derivative of a function?


How can I analytically differentiate in Python?

E.g:

d/dx (x^3 * L * lambda /(pi*d))

Additional: Screenshot of an attempt to install sympy


Solution

  • You can use sympy to differentiate a function symbolically

    >>> from sympy import *
    >>> x, L, lamb, d = symbols('x L lamb d')
    >>> f = x**3 * L * lamb / (pi * d)
    >>> f
    L*lamb*x**3/(pi*d)
    >>> diff(f, x)
    3*L*lamb*x**2/(pi*d)