0
$\begingroup$

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}]
$\endgroup$
  • $\begingroup$ …and if the curve is tangent to the $x$-axis, what color do you want? $\endgroup$ – J. M. is away May 18 '15 at 10:16
2
$\begingroup$

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.

Manipulate[
    {
     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@
        {PointSize[Large], 
         RGBColor[
           HeavisideTheta[-Last@#] (-Last@#), 
           HeavisideTheta[Last@#] Last@#,
           0],
         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}]

Result

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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