How to set the derivative of a function to zero? [duplicate]

Maybe this is very basic, but I'm not getting it. I've googled around and searched here for an answer but I can't find it. I need to set D[h[r], r] equal to zero, so that when this is evaluated it shows that it's zero. I've tried doing:

Block[D[h[r], r], 0]


or even just

D[h[r], r] = 0


but this returns "tag is protected". Thank you for your help

• Could you show Mathematica expressions instead of LaTeX? Jul 19, 2015 at 23:44
• Why do you need it to be zero? Is this to solve for something? Having the code would help. Jul 19, 2015 at 23:56

You can specify upvalues for any symbol. Try defining one on h as follows:

h /: D[h[r_], r_] := 0
UpValues[h]


As a result

D[h[x], x]==0
(* True *)

• I tried this, but instead I used: $$h_{rr}[r,\theta,\phi]$$ for h instead. I got the error "Argument at position 1 is expected to be a symbol. >>" h is some function which will need to approximated later on in the code. One way I can make the entire output an approximation is by cutting off this derivative Jul 20, 2015 at 1:43
• No one can help with your error unless you give us the actual Mathematica expression that produced it.
– Ian
Jul 20, 2015 at 1:45
• Okay. I tried it this way: h11 /: D[h11, r] := 0 UpValues[h11] This returns TagSetDelayed::tagnf: Tag h11 not found>> Jul 20, 2015 at 1:55
• I'm a bit stumped, because h11 /: D[h11, r] := 0 doesn't give me an error. It's also not going to solve your problem though, because without underscores it will only match the literal expression D[h11,r]. You can add additional arguments to the answer I gave like this: h /: D[h[r_, t_, p_], r_]:=0
– Ian
Jul 20, 2015 at 3:11