pythonsympyderivativeabsolute-value

Sympy absolute value derivativ


I've been trying to represent the absolute value derivative using sympy as the one shown in the image. I know that sympy represent it with real and imaginary part, but I need the derivative in function of the absolute value since I'm only working with real numbers. Thanks :)

enter image description here

I just have tried with the sympy functions, but as I mentioned before the derivative of the absolute value is given in complex terms


Solution

  • Use assumptions, like this:

    from sympy import *
    t = symbols("t")
    u = Function("u", real=True)(t)
    diff(Abs(u), t)
    # sign(u(t))*Derivative(u(t), t)