I have the following function and I use manipulate to change the plot of the function and the integral respectively. In nonlinear dynamics one plots a little circle/point on the intersections of the (left) graph with the x-axis. If the slope at the point of intersection is negative the circle/point is black, if the slope is positive, the point is white.

I want to do the same (only for the left graph), but dependent on the magnitude of the slope at the point of intersection (with the x-axes), I want to color the circles continuously, e.g. light green for a small negative slope at this point, getting more and more dark as the magnitude of the slope becomes more negative and the same for a positive slope e.g. red.

Any help appreciated!

 f[x_, a_, b_] := a x - b x^3

Manipulate[{Plot[f[x, a, b], {x, -2, 2}], 
  n = -\[Integral]f[x, a, b] \[DifferentialD]x; 
  Plot[n, {x, -2, 2}, PlotRange -> Automatic]}, {{a, 1/2, 
   "control parameter"}, -1, 2, 
  0.1}, {{b, 1/4, "control parameter 2"}, -1, 2, 0.1}]
  • $\begingroup$ …and if the curve is tangent to the $x$-axis, what color do you want? $\endgroup$ May 18, 2015 at 10:16

1 Answer 1


Might you be looking for this?

The modifications are in the addition of the zeros table (though it would be much better to write down an analytical expression) and the rule for Epilog acts on it accordingly to generate the points. In my example, though, they are black for a small slope and become brighter red/green for larger negative/positive slopes. You can modify the arguments of the RGBColor function to adjust coloring to your needs.

     zeros = {#, (1/2 (Derivative[1, 0, 0][f])[#, a, b])} & /@
        (x /. NSolve[f[x, a, b] == 0, x, Reals]);

  Plot[f[x, a, b], {x, -2, 2}, 
   Epilog -> (Flatten@
           HeavisideTheta[-Last@#] (-Last@#), 
           HeavisideTheta[Last@#] Last@#,
         Point[{First@#, 0}]} & /@ zeros)],

  n = -\[Integral] f[x, a, b] \[DifferentialD] x;

  Plot[n, {x, -2, 2}, PlotRange -> Automatic]},
  {{a, 1/2, "control parameter"}, -1, 2,  0.1},
  {{b, 1/4, "control parameter 2"}, -1, 2, 0.1}]


  • $\begingroup$ yes, that's exactly what I meant, thank you! $\endgroup$
    – holistic
    May 18, 2015 at 10:35
  • 1
    $\begingroup$ One more possible color function: Blend[{Green, White, Red}, 1/(1 + Exp[-x])]. $\endgroup$ May 18, 2015 at 10:49

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.