4
$\begingroup$

After having read the manuals and searched extensively, I could not find a way to do the following.

Suppose you have an implicit equation of the form

$y^4 + y^5 = x$, and $y$ is a function of $x$.

Now, using ContourPlot, one can easily graph y against x. However, I would like to know if there is a method to graph y' against x (i.e. $dy/dx$ against x). I haven't come across any such thing yet.

$\endgroup$
1
  • $\begingroup$ You can get the solution with something like sol[x_] = y /. Solve[y^4 + y^5 == x, y] and solp[x_] = D[#, x] & /@ sol[x]. $\endgroup$ Commented May 28, 2013 at 14:18

3 Answers 3

5
$\begingroup$

I suppose you wanted something like this:

ContourPlot[Evaluate[
                     Eliminate[{y^4 + y^5 - x == 0, Dt[y^4 + y^5 - x == 0, x]} /.
                               Dt[y, x] :> yp, y]],
            {x, -7, 7}, {yp, -7, 7}, PlotPoints -> 75]

implicit function's derivative

The key here is the use of Dt[] to differentiate the implicit Cartesian equation, and Eliminate[] to eliminate y; in this case, we have an algebraic equation and Eliminate[] had no difficulty, but this technique will be less successful once transcendental functions are involved.

$\endgroup$
11
  • $\begingroup$ Well, this is not plotting anything for me! $\endgroup$
    – piedpiper
    Commented May 28, 2013 at 14:31
  • $\begingroup$ Really? Did you copy the code into Mathematica? What version/OS are you on? $\endgroup$ Commented May 28, 2013 at 14:32
  • $\begingroup$ Windows 7 Pro, Mathematica 9. i copied the exact code. $\endgroup$
    – piedpiper
    Commented May 28, 2013 at 14:35
  • $\begingroup$ Very peculiar. No error messages whatsoever? $\endgroup$ Commented May 28, 2013 at 14:36
  • 1
    $\begingroup$ Well now that you mention it, I typed it and got the graph! Thanks! $\endgroup$
    – piedpiper
    Commented May 28, 2013 at 14:51
5
$\begingroup$

One easy way would be to use the ParametricPlot. Indeed, since y'(x)=1/x'(y) and

 x[y_] := y^4 + y^5;

one finds that y' is expressed as

 1/D[x[y], y]

yielding

1/(4 y^3 + 5 y^4)

Than one can plot as follows. Evaluate it:

    ParametricPlot[{y^4 + y^5, 1/(4 y^3 + 5 y^4)}, {y, 0.3, 1.2}, 
 AxesLabel -> {"x", "y'"}]

enter image description here

$\endgroup$
4
$\begingroup$

You can take the ContourPlot of the equation and replace all the y coordinates with the value of the derivative. This will be a fast transformation of the ContourPlot, but the main drawback is that the adaptive plotting algorithms are applied to the original equation, not to the derivative. Rapid changes in the derivative and exclusions will not be handled automatically.

The basic idea can be achieved like this.

f = y^4 + y^5 - x;
dydx[f_] := dydx[f] = -D[f, x]/D[f, y] /. {x -> #1, y -> #2} &;
pl = ContourPlot[f == 0, {x, -3, 3}, {y, -3, 3}];
pl /. GraphicsComplex[pts_, rest___] :> GraphicsComplex[{#1, dydx[f][##]} & @@@ pts, rest]

plot of dy/dx

One might also wish to automate this. One problem above is that it might happen that D[f, y] is zero. One might catch this and give back a very large derivative. There is an option showFunction to plot the original equation along with the derivative and another derivativeStyle to set the style of the dy/dx plot. (Note: The syntax coloring complains of a scope conflict in the definition of dfplot; changing Block[..] to Block @@ Hold[..] makes the annoying coloring go away. Both ways seem to work.)

ClearAll[dydx, dfplot];

dydx[f_, x_, y_] := With[{dfx = D[f, x], dfy = D[f, y]}, 
   dydx[f, x, y] = If[(dfy /. {x -> #1, y -> #2}) == 0,
      $MaxMachineNumber, -dfx/dfy /. {x -> #1, y -> #2}] &];

SetAttributes[dfplot, HoldAll];
Options[dfplot] = {showFunction -> False, 
    derivativeStyle -> Directive[ColorData[1][2]]} ~Join~ Options[ContourPlot];
dfplot[eqn_, domain1 : {x_, __}, domain2 : {y_, __}, 
  opts : OptionsPattern[]] := Block[{x, y},
  With[{f = eqn[[1]] - eqn[[2]],
        plot = ContourPlot[eqn, domain1, domain2, 
          Evaluate@FilterRules[{opts}, Options[ContourPlot]]]},
   Show[
    If[OptionValue[showFunction], plot, {}],
    plot /. GraphicsComplex[pts_, prim_, rest___] :> 
      GraphicsComplex[{#1, dydx[f, x, y][##]} & @@@ pts, 
       prim /. Tooltip[e_, label_] :> Tooltip[e, -D[f, x]/D[f, y]] /. 
         l_Line :> {OptionValue[derivativeStyle], l}, rest]
    ]
   ]
  ]

The OP's example:

dfplot[y^4 + y^5 == x, {x, -3, 3}, {y, -3, 3}, showFunction -> True]

Plot output

Another example for which J.M.'s eliminate method took too long:

dfplot[x^2 y - x^3 y^3 + 3 y^4 == 3, {x, -5, 7}, {y, -3, 3}, 
 showFunction -> True, PlotPoints -> 50]

Plot output

$\endgroup$
1
  • 1
    $\begingroup$ For sufficiently complicated algebraic functions, I'd probably replace Eliminate[] with GroebnerBasis[]: GroebnerBasis[{x^2 y - x^3 y^3 + 3 y^4 == 3, Dt[x^2 y - x^3 y^3 + 3 y^4 == 3, x] /. Dt[y, x] -> yp}, {x, yp}, y, MonomialOrder -> EliminationOrder] $\endgroup$ Commented May 29, 2013 at 2:14

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.