Reputation: 35
I want to calculate the derivative of a function of vector-functions based on derivative of vectors in Python using sympy. For example, if the function is:
f(g) = g(t) / (gT(t) * g(t)) ^ 0.5
then I want to have:
df/dt = [dg(t) / dt * (gT(t) * g(t)) ^ 0.5 - 0.5 * g(t) * (dgT(t) / dt * g(t) + gT(t) * dg(t) / dt) * (gT(t) * g(t)) ^ (-0.5)] / [gT(t) * g(t)]
In which gT(t) is transpose of the vector function g(t). How can I do that?
Upvotes: 0
Views: 473
Reputation: 19093
The derivative can be calculated with
>>> from sympy.abc import t
>>> g = Function('g', commutative=False)
>>> gT = Function('gT', commutative=False)
>>> f = g(t) / sqrt(gT(t) * g(t))
>>> f.diff(t).simplify()
(-g(t)*(gT(t)*g(t))**(-1/2)*(gT(t)*Derivative(g(t), t) + Derivative(gT(t), t)*g(t))*(gT(t)*g(t))**(-1) + 2*Derivative(g(t), t)*(gT(t)*g(t))**(-1/2))/2
Upvotes: 3