Derivatives on index characters in sympy

I'm trying to do symbolic calculations (mostly derivatives) on time indexed variables using sympy. Using indexed characters like r [t] below throws an error:

from sympy import *
t = Idx('t',10)
r = IndexedBase('r')

diff(r[t],r[t])
diff(r,r)

ValueError: 
Can't differentiate wrt the variable: r[t], 1

      

Maybe the reason is that something went wrong here:

In [15]: r[t].indices
Out[15]: (t,)

      

The comma after the t index looks suspicious to me, but I have no idea what went wrong.

Does anyone know how to do this in sympy?

+3


source to share


1 answer


You can distinguish between symbols, functions and derived symbols. Will this work:



>>> t = Idx('t',10)
>>> r=Function('r')
>>> r(t).diff(r(t))
1
>>> var('t')
t
>>> r(t).diff(t)
Derivative(r(t), t)

      

+3


source







All Articles