Suppose that u(x,y)u(x,y) is a function, and x=rcostx=r \cos t, y=rsinty= r \sin t, then we can define a new function v(r,t):=u(x,y)v(r,t):=u(x,y) with x,yx,y replaced by the above equations. It is quite easy to compute vv’s derivatives, for example ∂rrv(r,t)\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

Then, my question is how to define a new rule, to make the output above look like:

sin2tutt+sin(2t)urt+cos2turr.

\sin^2tu_{tt}+\sin(2t)u_{rt}+\cos^2tu_{rr}.

=================

Related: Chain rule while differentiating and How to make traditional output for derivatives

– Jacob Akkerboom

Nov 19 ’13 at 12:13

=================

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]}

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]

Then

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

gives you

Need some explain of your code, I don’t understand.

– van abel

Nov 19 ’13 at 10:44

@vanabel I think it is pretty similar to RunnyKine’s code. I will add a little explanation 🙂

– Jacob Akkerboom

Nov 19 ’13 at 11:30

yes, I see. But I prefer Runykine’s simple and work almost the same as I expected. Thanks for your code all the same.

– van abel

Nov 20 ’13 at 11:04