2
$\begingroup$

Consider the following line of code:

D[x == y^3 + x y, x, NonConstants -> y]

The output would be:

1 == y + x D[y, x, NonConstants -> {y}] + 3 y^2 D[y, x, NonConstants -> {y}]

This is a confusing and cumbersome notation for the more natural:

1 == y + x y' + 3y^2 y'

I am trying to use the Notation package to help me replace the messy, default, output with the more natural one.
I have not succeeded.

Of-course I have read this Q. The answer, if relevant, seems inaccessible to me, unfortunately.
Any help would be appreciated.

$\endgroup$
8
  • $\begingroup$ Related or a duplicate: How to make traditional output for derivatives. Otherwise you should improve your question to make it clearer. $\endgroup$
    – Artes
    Oct 8, 2013 at 20:03
  • $\begingroup$ @artes: I don't see how I can change the display/notation of an implicit derivative using the answers supplied. Can you? $\endgroup$
    – Trevor
    Oct 8, 2013 at 21:20
  • $\begingroup$ expr /. D[y, x, NonConstants -> {y}] :> y'[x] yields 1 == y + x y'[x] + 3 y^2 y'[x]. $\endgroup$
    – Artes
    Oct 11, 2013 at 21:55
  • $\begingroup$ @Artes, thanks for the reply. Is there a way to make such a change permanent? As it is, it seems I need to post-fix each expression with your addition. $\endgroup$
    – Trevor
    Oct 11, 2013 at 22:10
  • $\begingroup$ I'm not sure what you are asking but I guess if you have more equations you can do it once e.g. { l1==r1, l2==r2,..., ln==rn} /. D[y, x, NonConstants -> {y}] :> y'[x]. $\endgroup$
    – Artes
    Oct 11, 2013 at 22:29

2 Answers 2

1
$\begingroup$

Based on the comments above I believe you are merely looking for a way to automate Artes' replacement. Using $PrePrint:

$PrePrint = # /. {D[y_, x_, NonConstants -> {y_}] :> y'[x]} &;

Now:

D[x == y^3 + x y, x, NonConstants -> y]
1 == y + x y'[x] + 3 y^2 y'[x]

You could also use $Post or Format or MakeBoxes depending on your specific needs.
Using MakeBoxes is usually robust and does not tie up $Post or $PrePrint.

MakeBoxes[D[y_, x_, NonConstants -> {y_}], fmt_] := ToBoxes[y'[x], fmt]
$\endgroup$
1
  • $\begingroup$ @Wizard Thanks. Just what I was looking for :) $\endgroup$
    – Trevor
    Oct 18, 2013 at 10:37
3
$\begingroup$

I would consider using Dt:

Dt[x == y^3 + x y, x]
(* 1 == y + x Dt[y, x] + 3 y^2 Dt[y, x] *)

You can specify literal constants with SetAttributes:

ClearAll[a];
SetAttributes[a, Constant];
Dt[(x^2 + y^2)^2 == a^2 x y, x]
(* 2 (x^2 + y^2) (2 x + 2 y Dt[y, x]) == a^2 y + a^2 x Dt[y, x] *)

If x and y might become dependent variables, then omit the second argument and you get:

de = Dt[(x^2 + y^2)^2 == a^2 x y]
(* 2 (x^2 + y^2) (2 x Dt[x] + 2 y Dt[y]) == a^2 y Dt[x] + a^2 x Dt[y] *)

You can turn y into an explicit function of x:

de /. y -> y[x]
(* 2 (x^2 + y[x]^2) (2 x Dt[x] + 2 Dt[x] y[x] y'[x]) == a^2 Dt[x] y[x] + a^2 x Dt[x] y'[x] *)

If you want to turn x into the dependent variable, you can replace Dt[x] by 1:

de /. y -> y[x] /. Dt[x] -> 1
(* 2 (x^2 + y[x]^2) (2 x + 2 y[x] y'[x]) == a^2 y[x] + a^2 x y'[x] *)
$\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.