Reputation: 13
How to get kth derivative of f(x) where k is also a dummy index in summation. sym.diff(f,x,n) is interpreted as derivative of f with respect to both x and k not as kth derivative of f(x) which is what I want. The problem I have is in this expression
sym.Sum((1/sym.factorial(k)*sym.diff(fun,x,k)*(x-a)**k),(k,0,10))
Any suggestions? I want to some over kth derivatives as in taylor series, however, I don't know how to make sympy interpret k as number - order of the derivative (coming from the summation) and not a variable when it comes to the differentiation. The problem: how sum evaluates to zero
Upvotes: 1
Views: 327
Reputation: 14500
I'm not sure I understand what you want but I guess you need to pass a tuple (x, k)
like diff(f, (x, k))
rather than diff(f, x, k)
. Like this:
In [1]: import sympy as sym
In [2]: x, k, a = sym.symbols('x, k, a')
In [3]: fun = Function('f')(x)
In [4]: sym.Sum((1/sym.factorial(k)*sym.diff(fun,(x,k))*(x-a)**k),(k,0,10))
Out[4]:
10
______
╲
╲
╲ k
╲ k d
╲ (-a + x) ⋅───(f(x))
╱ k
╱ dx
╱ ───────────────────
╱ k!
╱
‾‾‾‾‾‾
k = 0
In [5]: _.doit()
Out[5]:
10 9 8 7 6 5
10 d 9 d 8 d 7 d 6 d 5 d
(-a + x) ⋅────(f(x)) (-a + x) ⋅───(f(x)) (-a + x) ⋅───(f(x)) (-a + x) ⋅───(f(x)) (-a + x) ⋅───(f(x)) (-a + x) ⋅───(f(x)) (-a + x
10 9 8 7 6 5
dx dx dx dx dx dx
───────────────────── + ─────────────────── + ─────────────────── + ─────────────────── + ─────────────────── + ─────────────────── + ───────
3628800 362880 40320 5040 720 120
4 3 2
4 d 3 d 2 d
) ⋅───(f(x)) (-a + x) ⋅───(f(x)) (-a + x) ⋅───(f(x))
4 3 2
dx dx dx d
──────────── + ─────────────────── + ─────────────────── + (-a + x)⋅──(f(x)) + f(x)
24 6 2 dx
Upvotes: 2