Background, this seems to work (This is manually transcribed from the program, beware of errors):

J1[f_, i_] := DifferenceDelta[f[i], i]^2
D[J1[f + t v, i], t]
2 (-v[i] + v[i+1]) (-(f + t v)[i] + (f + t v)[i+1])

What I would like to do is replace the ()^2 with a generic function JJ, and later specify

JJ[x_] := ...

Here's what happens with the generic JJ:

J2[f_, i_] := JJ[DifferenceDelta[f[i], i]]
D[J2[f + t v, i],t]

Why can't it return a derivative expression in terms of a generic derivative JJ', and how could I modify my code to make it work?

  • 1
    $\begingroup$ I get (-v[i] + v[1 + i]) Derivative[1][JJ][-(f + t v)[i] + (f + t v)[1 + i]], not 0. It may still not be what you want. If you're getting 0, then you might want to quit the kernel and try again. Perhaps v has the value 0. $\endgroup$ – Michael E2 Jun 7 '14 at 11:58
  • $\begingroup$ I think the issue was caused by a typo in the original post (tv was used instead of t v in D[J2[...]]); and now, with Michael's edit, it is fixed :) $\endgroup$ – kglr Jun 7 '14 at 13:22

Like this?

JJ[x_] := x^2

J2[f_, i_] := JJ[ DifferenceDelta[ f[i], i]]

D[ J2[ f + t v, i], t]
2 (-v[i] + v[1 + i]) (-(f + t v)[i] + (f + t v)[1 + i])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.