Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
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. –  Michael E2 Jun 7 '14 at 11:58
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 :) –  kglr Jun 7 '14 at 13:22

1 Answer 1

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])
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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