2017-09-25 111 views
0

我想使用sympy和某種擴展或簡化函數將(L + L')'轉換爲L'+ L''。如何將sum的抽象衍生物改寫爲sympy中衍生物的總和?

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的總和?

回答

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