The following piece of Mathematica code calculates the total derivative of a function $f(x,y(x))$ and compares it with what it should be. However, the result is not zero:

ff = f[x,y[x]];
Dt[ff,x] - (D[ff,x] + D[ff,y[x]] y'[x]) // FullSimplify

I can see that that


gives the total derivative as well and not $\partial f/\partial x$ while keeping $y(x)$ fixed. What am I missing here?

  • $\begingroup$ D is applying the chain rule. What else would you expect? If y were e.g. Sqrt or Sin, would you expect D[f[x, Sin[x]], x] == f'[x, Sin[x]]? $\endgroup$ – Niki Estner Mar 18 '16 at 11:28
  • $\begingroup$ Maybe what you want is: ff = f[x, y]; Dt[ff, x] - (D[ff, x] + D[ff, y] Dt[y, x]) $\endgroup$ – Niki Estner Mar 18 '16 at 11:28
  • $\begingroup$ If I understand this correctly, this initially treats $x$ and $y$ as two independent variables (first command). This means that I cannot use y'[x] in the second command but, instead, the total differential Dt[y,x]. $\endgroup$ – Roman Mar 18 '16 at 14:55
  • $\begingroup$ Nikie, this helps a lot. D[y,x] is zero as it probably treats $y$ as a constant, whereas D[y[x],x] is the same as y'[x]. But when we use just y, one must take Dt[y,x] instead. $\endgroup$ – Roman Mar 18 '16 at 15:12

You have to take a close look at what is happening in your example. As you created two functions f, ff that both depend on only one real valued variable x, Dt[ff,x] and D[ff,x] have to be the same. Essentially the Jacobi matrix delivered by Dt consists only of $\frac{\partial ff}{\partial x}$.

To come back to your specific example you are making the mistake of using D[ff,x] when you only want the derivative of f with respect to its first component at the point {x, y[x]}. So what you really want is the following:

ff[x_, z_] := f[x, z]
Dt[ff[x, y[x]], x] - ((D[ff[x, z], x] /. z -> y[x]) + D[ff[x, y[x]], y[x]] y'[x]) // FullSimplify

Note that (D[ff[x, z], x] /. z -> y[x]) is the derivative of f with respect to its first component evaluated at {x, y[x]}.

  • $\begingroup$ I see, this is a bit more complicated but works fine when I explicitly write ff[x,y[x]]. $\endgroup$ – Roman Mar 18 '16 at 15:44

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