In this demonstration I'm working on, I would like to plot a piecewise function with the tangent line to the function at a point that is determined by c
in the code below.
f[x_] = Piecewise[{{-x, x < 0}, {x^2, x >= 0}}];
g[x_] = Piecewise[{{-1, x < 0}, {2 x, x > 0}}];
Manipulate[
Plot[{f[x], f[c] + g[c] (x - c)}, {x, -3, 3}, Epilog -> Point[{c,f[c]}]],
{c, Range[-2, 2, .025], ControlType -> Slider}]
Is there some way to restrict the increment c
so that when it's negative, the increment size is the default size, whereas when it's positive, the increment size is something a bit smaller? I'm trying to make it easier to see that the derivative from the right approaches $0$. I'm not sure how to properly use an If
command to this end.
Join[Range[-2, 0, 0.025],Range[0.01, 2, 0.01]]
. But you can't useIf
. $\endgroup$