       Re: derivatives of indexed variables

• To: mathgroup at smc.vnet.net
• Subject: [mg2653] Re: derivatives of indexed variables
• From: sherod at boussinesq.Colorado.EDU (Scott Herod)
• Date: Thu, 30 Nov 1995 21:04:35 -0500
• Organization: University of Colorado at Boulder

```(Original article follows)

Mathematica does not know the difference between indexed functions
and functions of an integer.  Apparently when you try to compute the
derivative of something like a you get

Dt[a,x] = Dt[1,x]*Derivative[a]

This is useful if you want to make constants without having to worry about
derivatives acting correctly.  Unfortunately it makes it hard to create
indexed functions.

One workaround that I have used is to move back and forth between two forms
of the function a[i].  I create a sequence of functions a1, a2, etc
and convert between them using;

Cat[dumx_,dumy_] := ToExpression[StringJoin[ToString[dumx],ToString[dumy]]];
subI = {a[i_] :> Cat[a,i]};

and

subII = Table[Cat[a,i] -> a[i], {i,numberofa}]

=================================
In:= a /. subI

Out= a4

In:= numberofa = 10

Out= 10

In:= a4 /. subII

Out= a
=================================

Of course this is pretty crude and requires that you know how many indexed
functions you are going to have.

A second method is to make "a" an array of Function objects.

For example:
===================================
In:= Clear[a]

In:= a = {Sin, Cos, (1 + #)^2 &};

In:= a[][t]

Out= Sin[t]

In:= a[][x]

2
Out= (1 + x)
==================================

Then you can differentiate elements of the vector "a"

=================================

In:= Dt[a[],x]

2
Out= Dt[(1 + #1) , x] &

In:= %[x^2]

2
Out= 4 x (1 + x )
=================================

Scott Herod
Applied Mathematics

In article <49je70\$53i at dragonfly.wri.com>, george at mech.seas.upenn.edu ( George Jefferson ) writes:
|> What am I missing?
|>
|> total derivative of unspecified y:
|>
|> In:= Dt[y,x]
|>
|> Out= Dt[y, x]
|>
|> But if we take the derivaitve of an undefined indexed variable
|> it is assumed to be a constant..
|>
|> In:= Dt[a,x]
|>
|> Out= 0
|>
|> note however that the indexed symbol could easily represent a non-constant.
|>
|> In:= a=y; Dt[a,x]
|>
|> Out= Dt[y, x]
|>
|>
|> clearly the trouble is that there is no distinction between an indexed
|> symbol and a function evaluated at a fixed point..
|> Is there a workaround?

```