If I have two functions like these f[a_,b_] and g[a_,b_]. Lets say

f[a_,b_]:= a^2 + b 
g[a_,b_]:= a + b

some times I encounter Dt[f[a,b] , g[a,b]] and I want to have a defined value for this derivative, like Dt[f[a,b] , g[a,b]]-> R1 How can I define new derivative for this problem in Mathematica?

I mean whenever I differentiate f with respect g I get R1.

  • $\begingroup$ I think in order to know the correct way to do this, we need more context about your problem (and the previous question you asked doesn't contain enough context). $\endgroup$
    – march
    Nov 24, 2015 at 23:45
  • $\begingroup$ I tried to make it more clear $\endgroup$
    – amin bk
    Nov 24, 2015 at 23:52

2 Answers 2

protected = Unprotect[Dt]


Dt[f[___], g[___]] := R1

Dt[f[a, b], g[]]


Clear your definition


Dt[f[], g[]]



If your definition is no longer needed Clear it - otherwise you might get unwanted results in other areas. And restore protection:




Problem with defining such derivatives is that Dt doesn't hold its arguments, so if f and g have some definitions

ClearAll[f, g]
f[a_, b_] := a^2 + b
g[a_, b_] := a + b

then they are evaluated when passed to Dt, so "standard trick" with defining UpValues like:

f /: Dt[HoldPattern@f[a_, b_], HoldPattern@g[a_, b_]] := r1[a, b]

will not work.

What you can do is to use an "environment", in which this derivative will have desired value.

ClearAll[f, g]
f[a_, b_] := a^2 + b
g[a_, b_] := a + b

SetAttributes[withMyDerivative, HoldFirst]
withMyDerivative[expr_] :=
        g /: Dt[f[a_, b_], g[a_, b_]] := r1[a, b];

Now, inside withMyDerivative environment, Dt[f[a_, b_], g[a_, b_]] will evaluate to r1[a, b].

g[a, b] (f[a, b] + Dt[f[a, b], g[a, b]]) // withMyDerivative
(* (a + b) (a^2 + b + r1[a, b]) *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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