How to take a partial derivative



>
> maybe if there is a function which shows the explicit and implicit
> dependencies, I can write my own partialdiff function.


# I found that "dependencies" lists all dependencies. In my case:

dependencies;

(%i21) dependencies;
(%o21)                           [V(x), x(t)]
(%i22)

# I thought that for a function which will be called such that:
partialdiff(function, variable);
# I can look at all elements of this array and if there is an element, f(x),
of which f=function and x=variable, then take the derivative, because f
depends x explicitly, but if no such element found then give 0.
# I tried to implement this idea:

partialdiff(fun, var):=
block([dep,N,depexp], depexp: false, dep: dependencies, N: length(dep),
(for i:1 step 1 while i<=N
  do if (part(dep[i],0) = fun) and (part(dep[i],1)=var) then
    depexp:true),
if depexp then diff(fun,var) else 0);

# Which gives:

(%i19) partialdiff(V,t);
                                      dV
(%o19)                                --
                                      dx
(%i20) partialdiff(V,t);
(%o20)                                 0


# This is my solution, which needs explicit definitions of dependencies
before hand. But I am not sure if it can handle another cases.
-u?ur-