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

  • 1
    Do you mean D[f[x, y]/g[x, y], y]? – Moo Dec 6 at 12:44
  • hh[x_, y_] := D[f[x, y]/g[x, y], y]; hh[1,0] returns an error – Chipa-Chipa Dec 6 at 12:54
  • 2
    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 at 13:02
up vote 2 down vote accepted

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 2 days ago
  • @Chipa-Chipa & is a delimiter before (left to) which lies the scope of the pure function. – Αλέξανδρος Ζεγγ 2 days ago

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.