Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I force Mathematica to calculate symbolically the partial derivative of a function u[x,y] with respect to a variable z = f(x, y), where f(x, y) is known?

u is a function, defined on reals, taking real values. Same thing holds for f.

I want to try different changes of variables in PDEs. An example of what I'm trying to achieve and why it's failing:

z = 2*x + y 

2 x + y

D[u[x, y], z]

General::ivar: 2 x+y is not a valid variable. >>

D[u[x, y], 2*x + y]

EDIT: It appears I have failed to convey the essence of the question.

I am not asking how to solve a PDE with Mathematica. I am asking how, given a transformation of the original variables, to calculate the partial derivatives with respect to the new variables. The PDE part is merely some context as to why I want to do this.

share|improve this question
In general, the quantity you ask for is not well-defined. For example, for z = x + I y, the derivative of f(x,y) w.r.t. z exists only for holomorphic functions, which is a strong requirement. So, you have to first define exactly what you look for. – Leonid Shifrin Feb 21 '13 at 17:10
I am talking about functions, defined only in the real domain, however I am not assuming that f will always be linear in x and y. – K.Steff Feb 21 '13 at 17:17
If you start with two variables, then a transformation is specified completely only if you have two equations defining two new variables. It also has to be locally invertible. – Jens Feb 21 '13 at 17:27
@Jens I agree, however after defining a transformation, making sure it is locally invertible, you have to calculate the partial derivatives with respect to the new variables. This is the part that I want Mathematica to do, since it is extremely error-prone, especially with higher-order derivatives. – K.Steff Feb 21 '13 at 17:40
up vote 3 down vote accepted

In addition to belisarius' concrete answer, here is a more symbolic formulation:

If u and v are the new variables and the transformation functions are known to be

{x[u, v], y[u, v]}

then the set of partial derivatives of f with respect to u and v (i.e., the gradient) is

D[f[x, y], {{x, y}}].D[{x[u, v], y[u, v]}, {{u, v}}]

$\left\{ \\ f^{(1,0)}(x,y) x^{(1,0)}(u,v)+f^{(0,1)}(x,y)y^{(1,0)}(u,v), \\ f^{(1,0)}(x,y) x^{(0,1)}(u,v)+f^{(0,1)}(x,y)y^{(0,1)}(u,v)\\ \right\}$

share|improve this answer
Nice answer. I wonder how to format that last line in a more reasonable way :( – Dr. belisarius Feb 21 '13 at 18:31

Not sure if this is what you want. Anyway:

Suppose we define new coordinates:

{w == x + y, z == x - y}


sol = Solve[{w == x + y, z == x - y}, {x, y}];
FullSimplify@D[f[x, y] /. sol[[1]], z]

Let's try it:

f[x_, y_] := (x + y)^2
FullSimplify@D[f[x, y] /. sol[[1]], z]
(* 0 *)
FullSimplify@D[f[x, y] /. sol[[1]], w]
(* 2 w *)
share|improve this answer

You need to use Dt.

Dt[u[x, y], f[x, y]]

(* Dt[y, f[x, y]]*Derivative[0, 1][u][x, y] + Dt[x, f[x, y]]*Derivative[1, 0][u][x, y] *)
share|improve this answer
Now the big question is what Dt[y, f[x, y]] means. Try defining f[x_, y_] := x + y and see what happens. Basically the same as the error in the original question. – Jens Feb 21 '13 at 22:00
Good point. Why should Dt differentiate correctly w.r.t. f[x,y] but not w.r.t. Plus[x,y]? Anyway, the original question - i.e. the partial derivative of a function u[x,y] w.r.t. f[x, y] - is answered by Dt[u[x, y], f[x, y]]. – Stephen Luttrell Feb 22 '13 at 1:20

Your Answer


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.