Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}. $$

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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

share|improve this answer
add comment

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

Mathematica graphics

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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