# Define a partial derivative of a composite function

I would like to define the function $$\dfrac{\partial}{\partial y}\left(\dfrac{f(x,y)}{g(x,y)}\right)$$, for example

f[x_, y_] := x^2 + 3 y^3;
g[x_, y_] := x + 2 y;
g0[x_, y_] := f[x, y]/g[x, y];
h[x_, y_] := Derivative[0, 1][g0][x, y]


how is it possible to do it without using the intermediate function g0? the code

Derivative[0, 1][f/g][x, y]


is not working.

PS. Of course, one can differentiate by parts, but it is not the easiest solution

• Do you mean D[f[x, y]/g[x, y], y]? – Moo Dec 6 '18 at 12:44
• hh[x_, y_] := D[f[x, y]/g[x, y], y]; hh[1,0] returns an error – Chipa-Chipa Dec 6 '18 at 12:54
• That's because you are trying to differentiate with respect to the numbers 1 and 0 in this case... Try hh[xVal_, yVal_] := D[f[x, y]/g[x, y], y] /. {x -> xVal, y -> yVal}. Then it works with hh[1,0] as well as hh[x,y]. – Marius Ladegård Meyer Dec 6 '18 at 13:02

## 2 Answers

You can use a pure (anonymous) function in the middle

h[x_, y_] := Derivative[0, 1][f[#, #2]/g[#, #2] &][x, y]


as its name suggests, attaching a name to it is not a necessity.

Some testable results are

h[x, y] // FullSimplify
h[1, 0]

(-2 x^2 + 9 x y^2 + 12 y^3)/(x + 2 y)^2
-2

• thx. what does mean '&' in your code? – Chipa-Chipa Dec 11 '18 at 8:14
• @Chipa-Chipa & is a delimiter before (left to) which lies the scope of the pure function. – Αλέξανδρος Ζεγγ Dec 11 '18 at 9:18

Another possibility is to evaluate D before giving it numbers (i.e, use Set (=) instead of SetDelayed (:=) in the definition of h):

f[x_, y_] := x^2 + 3 y^3;
g[x_, y_] := x + 2 y;
h[x_, y_] = D[f[x, y]/g[x, y], y];


Then:

h[x, y]
h[1, 0]


(9 y^2)/(x + 2 y) - (2 (x^2 + 3 y^3))/(x + 2 y)^2

-2