MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

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


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]]


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
> answer my main question:
> 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,