代码之家  ›  专栏  ›  技术社区  ›  Rastapopoulos

不同区间上不同公式函数的导数

  •  1
  • Rastapopoulos  · 技术社区  · 8 年前

    是否有一种规范化的方法按部分声明函数 症状 ?我试过

    import sympy
    import sympy.functions.special.delta_functions as special
    
    sympy.init_printing()
    x = sympy.symbols('x', real=True)
    V = x*x * (special.Heaviside(x + 1) - special.Heaviside(x - 1)) \
        + (1 + 2*sympy.log(x)) * special.Heaviside(x - 1) \
        + (1 + 2*sympy.log(-x)) * special.Heaviside(-x - 1)
    

    它定义了一个可微函数,但是

    print(V.diff(x).simplify())
    # Prints: (x*(x**2*(-DiracDelta(x - 1) + DiracDelta(x + 1)) - 2*x*(Heaviside(x - 1) - Heaviside(x + 1)) - (2*log(-x) + 1)*DiracDelta(x + 1) + (2*log(x) + 1)*DiracDelta(x - 1)) + 2*Heaviside(-x - 1) + 2*Heaviside(x - 1))/x
    

    有什么方法可以告诉你 症状 简化 DiracDelta(x - a)*f(x) DiracDelta(x - a)*f(a) ?

    1 回复  |  直到 8 年前
        1
  •  2
  •   user6655984    8 年前

    Piecewise

    V = sympy.Piecewise((1 + 2*sympy.log(-x), x < -1),
                        (x**2, x < 1),
                        (1 + 2*sympy.log(x), True))
    print(V.diff(x)) 
    

    Piecewise((2/x, x < -1), (2*x, x < 1), (2/x, True))

    (expr, cond) Piecewise cond expr

    推荐文章