I am trying to find the derivative of a function defined in polar coordinates with respect to $x$ and $y$. My function is defined as follows:

$ v_x(r, \theta ) = v_r \cos (\theta ) - v_{\theta }\sin (\theta ) $

To do this, I start by defining the relation between Cartesian and Polar coordinates:

(* Define the mapping between Cartesian and Polar coordinate systems. *)
x[r_, θ_] = r Cos[θ];
y[r_, θ_] = r Sin[θ];

Then I define the function and find its derivative with respect to $x$:

Subscript[v, r][r_, θ_] = Subscript[v, r][r, θ] Cos[θ] - Subscript[v, θ][r, θ] Sin[θ];
D[Subscript[v, r][r, θ], x]

I am getting 0 because Mathematica is not considering the relation between $r$ and $x$. Is there anyway to tell Mathematica to use the chain rule to find the derivative of $v_x$ with respect to $x$?

The other problem is that Mathematica is considering the subscripts to be variables (which is reasonable), is there anyway to tell it that the subscripts are only notational symbols?

EDIT: The function is better defined as:

vx[r_, θ_] = vr[r, θ] Cos[θ] - vtheta[r, θ] Sin[θ];

to avoid evaluating subscripts and possibly having recursion.


2 Answers 2


In your case it might be more convenient to define the inverse transformation :

rho[x_, y_] = Sqrt[x^2 + y^2]
theta[x_, y_] = ArcTan[x, y]

 vx[r_, \[Theta]_] = vr[r, \[Theta]] Cos[\[Theta]] - vtheta[r, \[Theta]] Sin[\[Theta]];

Then this will use the chain rule :

 D[vx[rho[x, y], theta[x, y]], x]

One can simplify the result in terms of the polar coordinated :

Simplify[D[vx[rho[x, y], theta[x, y]], x] /. {x^2 + y^2 -> rho^2, ArcTan[x, y] -> theta, x -> rho Cos[theta], y -> rho Sin[theta]}, Assumptions -> {rho >= 0}]
  • $\begingroup$ This works but it produces everything in terms of x and y, which is very complicated! $\endgroup$
    – Rafid
    Aug 4, 2012 at 11:03
  • 2
    $\begingroup$ well if it works you could always upvote it to indicate that you appreciate his effort :) $\endgroup$
    – acl
    Aug 4, 2012 at 11:21
  • $\begingroup$ @Rafid Please see edit for some additional simplification. $\endgroup$ Aug 4, 2012 at 11:25
  • 1
    $\begingroup$ @b.gatessucks, for total conversion back to polar coordinates you will need to add x -> rho Cos[theta], y -> rho Sin[theta] to the replacement rules. $\endgroup$ Aug 4, 2012 at 11:41
  • $\begingroup$ @SimonWoods Thank you. $\endgroup$ Aug 4, 2012 at 12:06

You can use the total derivative Dt:

x[r_, \[Theta]_] = r Cos[\[Theta]];
y[r_, \[Theta]_] = r Sin[\[Theta]];

then for instance

Dt[a[r, \[Theta]]*Cos[\[Theta]] - b[r, \[Theta]]*Sin[\[Theta]], x]

does this

Mathematica graphics

I can't test your example because Subscript[v, r][r_, \[Theta]_] = Subscript[v, r][r, \[Theta]] Cos[\[Theta]] - Subscript[v, \[Theta]][r, \[Theta]] Sin[\[Theta]] hits the recursion limit (because the way it's defined and the evaluation sequence works, it'll never finish). However, here's how to indicate that something is a constant. Suppose I try:

Dt[Sin[\[Theta]] + c, x]

Mathematica graphics

but $c$ is a constant; I can indicate this like so:

Dt[Sin[\[Theta]] + c, x, Constants -> {c}]

Mathematica graphics

  • $\begingroup$ The problem with this solution is that it is not substituting the values and dr/dx and dtheta/dx, so it is not really making use of the Cartesian-Polar equations! $\endgroup$
    – Rafid
    Aug 4, 2012 at 12:46
  • $\begingroup$ @Rafid Right. So you expect to define x[r,Theta]:=etc and have Mathematica automatically insert the values for $\partial_x\theta$ etc? That's not going to be 2 lines of code. By the way, did you notice that the code in your question goes into infinite recursion? $\endgroup$
    – acl
    Aug 4, 2012 at 12:53
  • $\begingroup$ Well, honestly, I am relatively new to Mathematica, so I thought this might be possible since I am already passing in the relation. Anyway, thanks, one vote :-) And yes, I did notice the recursion, I am going to edit my question now. $\endgroup$
    – Rafid
    Aug 4, 2012 at 13:02

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.