2
$\begingroup$

I would like to draw the graph of $f(x)=x^{3}-x+2$ next to two buttons named: "Property1" and "Property2" in which when I press "Property1" it shows "f'(1) is positive", while for "Property2" it shows "f'(1)=2".

I am only able to draw my idea as follows:

f[x_] = x^3 - x + 2;
f'[x_] = 3*x^2 - 1;
pt1 = Plot[x^3 - 3*x + 1, {x, -1, 3}, PlotRange -> {-2, 6}];
pt2 = Manipulate[p[1], {p, {f, f'}}];
GraphicsRow[{pt1, pt2}]

enter image description here

Could someone give me a help? Thanks.

$\endgroup$
1
$\begingroup$
ClearAll[st, sign, f, g]
f[x_] := x^3 - x + 2;
g[x_] := x^3 - 3*x + 1;
sign[x_] := Sign[x] /. {-1 -> Negative, _ :> Positive}
st = {StringTemplate["f(``) = <* f[#]*>."],
   StringTemplate["f'(``) is <* sign[f'[#]]*>."]};

pt1 = Plot[g[x], {x, -1, 3}, PlotRange -> {-2, 6}, ImageSize -> 200];
pt2 = Manipulate[st[[p]][x],
   {x, 0, 1},
   {{p, 1}, {1 -> "Property 1", 2 -> "Property 2"}}];

Panel @ Row[{pt1, pt2}, Spacer[10]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks. You must be a dreamy teacher in any classroom. $\endgroup$ – Binjiu Feb 23 '20 at 9:27
  • $\begingroup$ Hi, is it possible to make an animation in the same picture with "Property 3" button, for e.g. making the point M running along the graph of g[x] from (0,1) to (1,-1) once "Property 3" taken action? Thanks. $\endgroup$ – Binjiu Feb 23 '20 at 9:42
  • 1
    $\begingroup$ @Binjiu, if you want the animation in the manipulate panel, you can define st = {StringTemplate["f(``) = <* f[#]*>."], StringTemplate["f'(``) is <* sign[f'[#]]*>."], Animate[Show[pt1, Epilog -> {PointSize[Large], Point[{x, g[x]}]}], {x, 0, 1}, Paneled -> False]} and pt2 = Manipulate[p /. {3 -> st[[3]], i_ :> st[[i]][x]}, {x, 0, 1}, {{p, 1}, {1 -> "Property 1", 2 -> "Property 2", 3 -> "Property 3"}}]; If you want the animation on the left panel, I cannot think of a simple modification of the current answer (maybe you can post it as a separate question). $\endgroup$ – kglr Feb 23 '20 at 9:59

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.