如何将和的抽象导数重写为同情中的导数之和?

时间:2017-09-25 17:43:08

标签: sympy

我想使用sympy和某种扩展或简化函数将(L + L')'转换为L'+ L''。

import sympy
sympy.init_printing() # math as latex
z, L = sympy.symbols('z,L')
expr = sympy.Derivative(L + sympy.Derivative(L,z), z)
expr

enter image description here

我尝试了expand之类的标准函数,它重写了表达式(即使标记为force=True),或者doit也返回零。

  

问题即可。有没有办法将sp.Derivative应用于两个函数的总和,并将其扩展为sp.Derivative的总和?

1 个答案:

答案 0 :(得分:2)

如果我们使用衍生品,最好使用sympy.Function代替sympy.Symbol。为了扩展导数,可以使用.doit()方法。

  

示例

import sympy
sympy.init_printing() # math as latex
z = sympy.Symbol('z')
f = sympy.Function("f")(z)
expr = sympy.Derivative(sympy.Derivative(f) + f)
expr

enter image description here

expr.doit()

enter image description here