11
$\begingroup$

I want to take a derivative of the inverse of a certain variable, e.g., being the function:

f[x_, a_, T_] := (a x^3)/T

I want the derivative with respect to $1/T$:

$$\frac{\partial f}{\partial \left(\frac{1}{T}\right)}=ax^3$$

It doesn't work with:

D[f[x, a, T], 1/T]

enter image description here

$\frac{\partial f(x,a,T)}{\partial \frac{1}{T}}$

neither if I define:

b=1/T

And then ask for:

D[f[x, a, b], b]

It always state "1/T is not a valid variable"

enter image description here

$\frac{\partial f(x,a,T)}{\partial \frac{1}{T}}$

$\endgroup$
  • 3
    $\begingroup$ Block[{c}, D[f[x, a, 1/c], c] /. c -> 1/T]. The Block is only there in case you happen to have c defined somewhere else. $\endgroup$ – march Dec 8 '16 at 21:03
  • $\begingroup$ I can't believe it was this simple. Appreciate!!! $\endgroup$ – RTS Dec 8 '16 at 21:19
  • $\begingroup$ @march Why do not you put this as an answer? That was interesting for me. I needed this information the other day and I had not found it. $\endgroup$ – LCarvalho Dec 8 '16 at 22:08
  • $\begingroup$ @march Seems simple to you, but to other users it's cool $\endgroup$ – LCarvalho Dec 8 '16 at 22:10
  • $\begingroup$ @LCarvalho. I mean, I would guess that this is a duplicate, but I only had time to do a little searching, so I haven't found one yet. Nonetheless, I'll quickly write something up. $\endgroup$ – march Dec 8 '16 at 22:20
11
$\begingroup$

you can also use the chain rule:

$$\frac{\partial f}{\partial \left(\frac{1}{T}\right)}=\frac{\frac{\partial f}{\partial T}}{\frac{\partial \frac{1}{T}}{\partial T}}$$

 D[f[x, a, T], T]/D[1/T, T]

a x^3

$\endgroup$
8
$\begingroup$

You had the right idea, except for Setting the value of b to be 1/T. The reason that doesn't work is that D does not have the Attribute HoldAll (or variants) which means that its arguments get evaluated before D does. That is, if you do

b = 1/T;
D[f[x, a, 1/b], b]

you get the error because 1/T has been put in place of b before the derivative is taken. The fix is to wrap the entire expression in the Block scoping construct, which will delay the evaluation of b until after the derivative is taken, like so:

f[x_, a_, T_] := (a*x^3)/T
b = 1/T;
Block[{b}, D[f[x, a, 1/b], b]]
(* a x^3 *)

Alternatively, use an undefined symbol and use a replacement rule. I prefer this version because I like to avoid cluttering up the global namespace with defined symbols. So:

f[x_, a_, T_] := (a*x^3)/T
Block[{c}, D[f[x, a, 1/c], c] /. c -> 1/T]
(* a x^3 *)
$\endgroup$
  • 1
    $\begingroup$ Now yes. Very good tip. $\endgroup$ – LCarvalho Dec 8 '16 at 22:30

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.