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

非交换函数乘积的导数

  •  1
  • mike  · 技术社区  · 7 年前

    如果我在symphy中使用函数并调用diff方法,交换属性就会被忽略。

    h = Function('h',real=True,commutative=False)(t)
    R = Function('R',real=True,commutative=False)(t)
    print(diff(R*h,t))
    # returns:
    R(t)*Derivative(h(t), t) + h(t)*Derivative(R(t), t)
    

    我是不是做错了什么?我只想让输出的R始终在前面。。

    1 回复  |  直到 7 年前
        1
  •  1
  •   user6655984 user6655984    7 年前

    这可以说是Symphy中的一个bug determines the commutativity of a function from its arguments .另请参见 this comment .它与衍生品无关:只是打印 h*R 将暴露错误(表达式显示为 R(t)*h(t) )。

    在更改此行为之前,似乎实现所需结果的唯一方法是声明 t 非交换性:

    t = Symbol('t', commutative=False)
    h = Function('h', real=True)(t)
    R = Function('R', real=True)(t)
    print(diff(R*h, t))
    

    印刷品

    R(t)*Derivative(h(t), t) + Derivative(R(t), t)*h(t)