我有一个在 SymPy 中的符号表达式,在对该表达式进行二阶导数之后,需要将其所有系数全部移除。以下是代码:
import sympy as sym
x, y = sym.symbols('x y')
# define the shape function
S_function = 0 +\
x + y +\
x**2 + x*y + y**2 +\
x**3 + x**2*y + x*y**2 + y**3
# take the 2nd derivative of the shape function for the x components
S_function_xx = sym.expand(sym.diff(S_function,x,2))
print(S_function_xx)
当我得到6*x + 2*y + 2的输出时,我需要将其转换为x + y。欢迎提供任何建议。