Suppose that $u(x,y)$ is a function, and $x=r \cos t$, $y= r \sin t$, then we can define a new function $v(r,t):=u(x,y)$ with $x,y$ replaced by the above equations. It is quite easy to compute $v$'s derivatives, for example $\partial_{rr}v(r,t)$ can be computed in MMA as

v[r_, t_] := u[x, y] /. {x -> r Cos[t], y -> r Sin[t]}

D[v[r, t], {r, 2}] // Simplify

The output of which looks like

enter image description here

Then, my question is how to define a new rule, to make the output above look like: $$ \sin^2tu_{tt}+\sin(2t)u_{rt}+\cos^2tu_{rr}. $$


2 Answers 2


How about this:

Simplify[D[v[r, t], {r, 2}]] /. {Derivative[0, 2][u_][__] :> 
   Subscript[u, tt], Derivative[1, 1][u_][__] :> Subscript[u, rt], 
  Derivative[2, 0][u_][__] :> Subscript[u, rr]}

enter image description here


This answer is similar to that of RunnyKine. The notation is a little bit different, which could be convenient if we want to differentiate more than two times.

Note that the OPs definition can probably for v can also be written as follows. The order of evaluation is a bit different, but the definition should otherwise be equivalent.

v[r_, t_] := u[r Cos[t], r Sin[t]];

I have made two rules, which I suppose could be merged into one. But it is nice to think about them this way. The rule rule below can change expressions containing Derivative (as the "highest head"), which is displayed like a superscript, into an expression with a subscript. I simply copy the the numbers which appear in the superscript notation and put them in the subscript notation, and in the subscript notation I add the names of the variables, r and t. The wrapper HoldForm is an unimportant detail.

rule =
 Derivative[a_, b_][u][r Cos[t], r Sin[t]] :> 
  Subscript[u, a HoldForm@r, b HoldForm@t ];

One thing is a bit tricky here, as perhaps some unexpected evaluation will occur. Subscript has no attribute like Hold or HoldAll, so its arguments will be evaluated, as usual. As a result 1*HoldForm[r] will evaluate to HoldForm[r] and 0*HoldForm[r] will evaluate to 0.

I like the way it looks, except that when we differentiate to some variable 0 times, I would rather not write anything than write 0. So I delete the 0's.

rule2 =
 sub_Subscript :>
  DeleteCases[sub, 0, Infinity]


D[v[r, t], {r, 2}] /. rule /. rule2 // Simplify

gives you

Mathematica graphics

  • $\begingroup$ Need some explain of your code, I don't understand. $\endgroup$
    – van abel
    Nov 19, 2013 at 10:44
  • $\begingroup$ @vanabel I think it is pretty similar to RunnyKine's code. I will add a little explanation :) $\endgroup$ Nov 19, 2013 at 11:30
  • $\begingroup$ yes, I see. But I prefer Runykine's simple and work almost the same as I expected. Thanks for your code all the same. $\endgroup$
    – van abel
    Nov 20, 2013 at 11:04

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.