Skip to main content
added 1333 characters in body
Source Link
Alexei Boulbitch
  • 40k
  • 2
  • 48
  • 100

I am not really sure that I understand your aim, but as to the simple example in the end of your question, this seems to do the job:

    Clear[x, y, u, v, f];
x = u^2 - u*v + v^2;
y = u^2 + 2 u*v - 3 v^2;
f = x^2 + y^2;
D[f, u] /. {x -> X, y -> Y}

(*  2 (2 u - v) X + 2 (2 u + 2 v) Y  *)

Have fun!

Later comment: To address your later question: In the first example the trick worked, since the expressions of the result:

    Clear[x, y, u, v, f];
x = u^2 - u*v + v^2;
y = u^2 + 2 u*v - 3 v^2;
f = x^2 + y^2;


 D[f, u]
    
    (* 
 2 (2 u + 2 v) *(u^2 + 2 u v - 3 v^2)* + 2 (2 u - v) *(u^2 - u v + v^2)* 
 *)

already contained the combinations exactly equal to x and y. I pointed them out by the asterixes in the answer. This enables one to directly apply the replacement. Your new example is different. If you make the calculation:

 Clear[x, y, f, t]
x = 2 t;
y = t^2;
f = x^2 y + x y^2;
D[f, t]

(*  16 t^3 + 10 t^4   *)

the result has no such a form as the previous one, and even more, one can represent its terms in many different ways as some products of x and y. One should decide, what he wants to achieve. What about the following:

 Clear[x, y, f, t]

f = x[t]^2 y[t] + x[t] y[t]^2;
Factor /@ (D[f, t] // Collect[#, {y'[t], x'[t]}] &)

(*  y[t] (2 x[t] + y[t]) Derivative[1][x][t] + 
 x[t] (x[t] + 2 y[t]) Derivative[1][y][t]   *)

?? Is it not closer to the chain rule?

If this is not what you are after, explain me please your target in more details.

Have fun!

I am not really sure that I understand your aim, but as to the simple example in the end of your question, this seems to do the job:

    Clear[x, y, u, v, f];
x = u^2 - u*v + v^2;
y = u^2 + 2 u*v - 3 v^2;
f = x^2 + y^2;
D[f, u] /. {x -> X, y -> Y}

(*  2 (2 u - v) X + 2 (2 u + 2 v) Y  *)

Have fun!

I am not really sure that I understand your aim, but as to the simple example in the end of your question, this seems to do the job:

    Clear[x, y, u, v, f];
x = u^2 - u*v + v^2;
y = u^2 + 2 u*v - 3 v^2;
f = x^2 + y^2;
D[f, u] /. {x -> X, y -> Y}

(*  2 (2 u - v) X + 2 (2 u + 2 v) Y  *)

Have fun!

Later comment: To address your later question: In the first example the trick worked, since the expressions of the result:

    Clear[x, y, u, v, f];
x = u^2 - u*v + v^2;
y = u^2 + 2 u*v - 3 v^2;
f = x^2 + y^2;


 D[f, u]
    
    (* 
 2 (2 u + 2 v) *(u^2 + 2 u v - 3 v^2)* + 2 (2 u - v) *(u^2 - u v + v^2)* 
 *)

already contained the combinations exactly equal to x and y. I pointed them out by the asterixes in the answer. This enables one to directly apply the replacement. Your new example is different. If you make the calculation:

 Clear[x, y, f, t]
x = 2 t;
y = t^2;
f = x^2 y + x y^2;
D[f, t]

(*  16 t^3 + 10 t^4   *)

the result has no such a form as the previous one, and even more, one can represent its terms in many different ways as some products of x and y. One should decide, what he wants to achieve. What about the following:

 Clear[x, y, f, t]

f = x[t]^2 y[t] + x[t] y[t]^2;
Factor /@ (D[f, t] // Collect[#, {y'[t], x'[t]}] &)

(*  y[t] (2 x[t] + y[t]) Derivative[1][x][t] + 
 x[t] (x[t] + 2 y[t]) Derivative[1][y][t]   *)

?? Is it not closer to the chain rule?

If this is not what you are after, explain me please your target in more details.

Have fun!

Source Link
Alexei Boulbitch
  • 40k
  • 2
  • 48
  • 100

I am not really sure that I understand your aim, but as to the simple example in the end of your question, this seems to do the job:

    Clear[x, y, u, v, f];
x = u^2 - u*v + v^2;
y = u^2 + 2 u*v - 3 v^2;
f = x^2 + y^2;
D[f, u] /. {x -> X, y -> Y}

(*  2 (2 u - v) X + 2 (2 u + 2 v) Y  *)

Have fun!