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.

  • 1
    $\begingroup$ 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. $\endgroup$ – Leonid Shifrin Feb 21 '13 at 17:10
  • $\begingroup$ 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. $\endgroup$ – K.Steff Feb 21 '13 at 17:17
  • 1
    $\begingroup$ 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. $\endgroup$ – Jens Feb 21 '13 at 17:27
  • $\begingroup$ @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. $\endgroup$ – K.Steff Feb 21 '13 at 17:40

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

| improve this answer | |
  • $\begingroup$ Nice answer. I wonder how to format that last line in a more reasonable way :( $\endgroup$ – 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 *)
| 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] *)
| improve this answer | |
  • $\begingroup$ 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. $\endgroup$ – Jens Feb 21 '13 at 22:00
  • $\begingroup$ 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]]. $\endgroup$ – Stephen Luttrell Feb 22 '13 at 1:20

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.