I am trying to plot a derivative versus the variable using ParametricPlot. Whenever I evaluate the two functions manually, I can manually find values for certain x, leading me to think that it should be able to plot something. Other related questions here only solve specific problems with the functions so I have not been able to improve my code with the answers I found.

The following is a minimum working example (sorry for the many definitions):

Some definitions:

Zc = (11 + 5*Sqrt[5])/(2)
Q[x_, n_] := Product[1 - x^i, {i, n}]
P[x_, n_] := Product[1 - x^(2 i - 1), {i, n}]
H[x_, n_] := Product[1/((1 - x^(5 i - 3))*(1 - x^(5 i - 2))), {i, n}]
G[x_, n_] := 
 Product[(1/((1 - x^(5 i - 4))*(1 - x^(5 i - 1)))), {i, n}]
z[x_, n_] := (-x*(H[x, n]^5))/(G[x, n]^5)
ρ[x_, n_] := (-x*G[x, n]*H[x^6, n]*P[x^3, n])/(P[x, n])
dρdx[a_, n_] := D[ρ[x, n], x] /. x -> a
dzdx[a_, n_] := D[z[x, n], x] /. x -> a
dρdz[x_, n_] := dρdx[x, n]/dzdx[x, n]

Some styling:

lineStyle = {Red, Dashed};
lineZc = Line[{{Zc, 0}, {Zc, 10}}];

The ParametricPlot call:

    {z[x, 10], dρdz[x, 10]}, {x, -1, 1},
    ImageSize -> Large,
    AspectRatio -> 1/2,
    PlotLabel -> 
   "Rate of change of density vs. fugacity around \!\(\*SubscriptBox[\
\(z\), \(c\)]\) for n=100",
    Prolog -> {Directive[lineStyle], lineZc},
    PlotLegends -> {"z<\!\(\*SubscriptBox[\(z\), \(c\)]\)", 
    "z>\!\(\*SubscriptBox[\(z\), \(c\)]\)"},
    PlotPoints -> 1000,
   AxesLabel -> {"z", "\!\(\*FractionBox[\(dρ\), \(dz\)]\)"},
    PlotRange -> Automatic

I am a new user so sorry if not all the formatting is up to par, let me know if I have to change anything.

Currently, my only guess is that is has to do something with the ReplaceAll command I am using for the derivatives, but I do not know how to dodge this way.

  • $\begingroup$ @HenrikSchumacher Thank you, that works like a charm! I did not know it worked like this. Is there a way I could accept your comment as an answer? And as for the numerical nightmare, yes, haha I agree. I am working on this, trying to find a better to handle approximation on the domain I need. $\endgroup$
    – user54666
    Commented Jan 14, 2018 at 14:32
  • $\begingroup$ Have a look at PadeApproximant or use Series to get suitable approximations for selected domains; these are often quite useful in numericizing analytic functions... When you have found suitable rational expression, you can apply Compile to them for getting performance. $\endgroup$ Commented Jan 14, 2018 at 15:00
  • $\begingroup$ I will do that! Thank you for your help. $\endgroup$
    – user54666
    Commented Jan 14, 2018 at 15:02
  • $\begingroup$ You're welcome! $\endgroup$ Commented Jan 14, 2018 at 15:02

1 Answer 1


Enforce computation of derivative at time of definition with

z[x_, n_] := Evaluate[(-x*(H[x, n]^5))/(G[x, n]^5)];
dρdz[x_, n_] := Evaluate[dρdx[x, n]/dzdx[x, n]];

Moreover, dρdz is a numerical nightmare as seemingly very large or very small quantities are divided by each other...


Your Answer

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