【问题标题】:The derivative of the product of non-commutative functions非交换函数乘积的导数
【发布时间】:2018-10-23 06:21:52
【问题描述】:

如果我在 SymPy 中使用函数并调用 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..

【问题讨论】:

    标签: python sympy commutativity


    【解决方案1】:

    这可以说是 SymPy 中的一个错误,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)
    

    【讨论】:

    • 哇,谢谢。但是,是的,我需要使 t 不可交换才能使其功能不可交换?!这是一个严重的设计决定,让我怀疑。
    猜你喜欢
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多