[英]Sum with index as derivative order
I want to define a sum that contains derivatives of a function, where the summation index is the derivative order. 我想定义一个包含函数导数的和,其中求和索引是导数阶。 Simple example:
简单的例子:
x, i = symbols("x i")
f = Function("f")(x)
Sum(diff(f,x,i), [i,1,3])
However, this only returns a sum of zeros. 但是,这仅返回零的总和。 I assume this is because it tries to differentiate f wrt x first, and then wrt i.
我认为这是因为它试图先区分f wrt x,然后再区分i。 Since f is not a function of i, it evaluates to zero before it is processed by the Sum function.
由于f不是i的函数,因此在由Sum函数处理之前 ,其值为零。 What I want to happen is
我想发生的是
diff(f,x,1)
diff(f,x,2)
diff(f,x,3)
etc. 等等
Is there a way to make this work? 有没有办法使这项工作?
sympy.diff(f,x,i)
is equivalent to i
'th order derivative of f
only if i
is an integer. sympy.diff(f,x,i)
到相当于i
“理论值的一阶导数f
仅当i
是一个整数。 In your case it is a symbol. 在您的情况下,它是一个符号。
Use instead the builtin sum()
along with a generator expression: 请改用内置
sum()
和生成器表达式:
>>> sum(diff(f,x,j) for j in range(1,4))
Derivative(f(x), x) + Derivative(f(x), x, x) + Derivative(f(x), x, x, x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.