Re: Differentiation w.r.t. elements of lists

• To: mathgroup at smc.vnet.net
• Subject: [mg79785] Re: Differentiation w.r.t. elements of lists
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Sat, 4 Aug 2007 05:56:55 -0400 (EDT)
• References: <f8pi48\$1l4\$1@smc.vnet.net> <f8s3e2\$38u\$1@smc.vnet.net> <f8v1i1\$dic\$1@smc.vnet.net>

```Hi,

you misunderstand the meaning of Part[] or x[[i]].
Part[] always reference an element of a List[] that
must exist, i.e., x[[2]] gives an error if x is a
symbol. You wish to interpret the index i as a function
argument and you have to write x[i].

Second, Sum[] is a build-in function that try to evaluate
it's argument to find a closed expression and because
Sum[f[i]+g[i],{i,0,Infinity}] may be convergent while
neither Sum[f[i],{i,0,Infintity}] nor Sum[g[i],{i,0,Infintity}]
is convergent, Mathematica will not split the Sum[] or do anything
else with it.

So it is wise not to use Sum[] for formal sums that
can't be evaluated.
The better way is to define sum[] and to setup the rule

sum /: D[sum[a_, {i_, i1_, i2_}], f_[k_]] :=
KroneckerDelta[i, k]*D[a, f[i]]

Regards
Jens

Daniel Hornung wrote:
> Jens-Peer Kuska wrote:
>
>> Hi,
>>
>> and you are shure that
>>
>>  > Another, even shorter test case would be
>>  >
>>  > D[x[[i]], x[[j]]]
>>  >
>>  > which "should", IMHO, return KroneckerDelta[i,j].
>>
>> ??
>>
>> Than
>> D[x[[1]],x[[2]]]
>>
>> should be zero ? right ?? but what is
>>
>> with
>>
>> x = {Sin[y], y}
>>
>> D[x[[1]], x[[2]]]
>>
>> the result is not 0 ..
>>
>> may be that you are wrong.
>>
>> Regards
>>    Jens
>>
>
> OK, I think I had thought wrongly there.  But sadly that still doesn't
> Why does the second line result in 0, and what could I do better?
>
>>> h[x_]:=Sum[x[[j]]^2,{j,1,Length[x]}]
>>> D[h[x],x[[i]]]
>
> --
> Daniel Hornung
> Max Planck Institute for Dynamics and Self-Organization
> G=C3=B6ttingen, Germany
>

```

• Prev by Date: Re: Convective diffusion equation in 2D
• Next by Date: Re: Possible mistake in ListPointPlot3D?
• Previous by thread: Re: Differentiation w.r.t. elements of lists
• Next by thread: Re: Unbearably slow plotting (v6)David Bailey,http://www.dbaileyconsultancy.co.ukDavid