2
$\begingroup$

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

$\endgroup$
3
  • 1
    $\begingroup$ Do you mean D[f[x, y]/g[x, y], y]? $\endgroup$
    – Moo
    Dec 6, 2018 at 12:44
  • $\begingroup$ hh[x_, y_] := D[f[x, y]/g[x, y], y]; hh[1,0] returns an error $\endgroup$ Dec 6, 2018 at 12:54
  • 2
    $\begingroup$ 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]. $\endgroup$ Dec 6, 2018 at 13:02

2 Answers 2

3
$\begingroup$

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
$\endgroup$
2
  • $\begingroup$ thx. what does mean '&' in your code? $\endgroup$ Dec 11, 2018 at 8:14
  • $\begingroup$ @Chipa-Chipa & is a delimiter before (left to) which lies the scope of the pure function. $\endgroup$ Dec 11, 2018 at 9:18
3
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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