Search code examples
variablesindexingmapledifferentiation

Derivatives of indexed variables in Maple


Consider N variables, x_1, x_2, ... , x_N. Given i < N and j < N, it holds dx_i/dx_j=delta_i,j, i.e. the derivative is 1 when i=j and 0 otherwise.

While diff(x[i],x[i]) returns 1, unfortunately diff(x[i],x[j]) returns 0 rather than delta_i,j and sum(diff(x[i],x[j]),j=1..N) returns 0 rather than 1.

Is there a way of getting the correct derivative without specifying the value of N? I.e. a way that can be used for calculations that hold for any N.


Solution

  • The regular diff() command handles the arguments in a literal manner. However, you can try the Physics package, and treat the metric as the Kronecker delta:

    restart;
    with( Physics ):
    Setup( metric = Euclidean ):
    Define( x ):
    
    f := diff( Sum( a[i] * x[i], i=1..N ), x[j] );
    Simplify( eval( f, g_=KroneckerDelta ) ) assuming j >= 1 and j <= N; # returns a[j]