3

This is a small adjustment I am making to a nice presentation from Welwyn Hollis's CalcLabs, Mathematica, Singe Variable Calculus.

slopeExplorer[fn_, {x_, xmin_, xmax_}, {y_, ymin_, ymax_}] :=
 DynamicModule[{f},
      f[t_] = fn /. x -> t;
      Manipulate[
       Show[
        Plot[{f[x], f[a] + f'[a] (x - a)}, {x, xmin, xmax},
         PlotStyle -> {Directive[Blue], Directive[Orange]},
         PlotRange -> {ymin, ymax},
         PlotLabel -> 
          Pane["Slope of tangent line = " <> 
            ToString[Round[f'[a], 0.01]]]],
        Plot[f'[x], {x, xmin - 0.01, a},
         PlotStyle -> Directive[Red, Dashed]],
        Graphics[{
          Gray, Line[{{a, f[a]}, {a, f'[a]}}],
          Red, PointSize[Medium], Point[{a, f[a]}],
          Blue, Point[{a, f'[a]}]
          }]
        ], {a, xmin, xmax}
       ]
      ]
    slopeExplorer[2 x^3 - 3 x^2 - 36 x, {x, -5, 6}, {y, -150, 150}]

I would like to make some adjustments to the PlotLabel I've added.

  1. As I move the slider, I'd like the PlotLabel to note jump about changing length, etc.

  2. I'd also like to add a line of space between the PlotLabel and the coordinate system.

Suggestions?

David
  • 14,883
  • 4
  • 44
  • 117

2 Answers2

4

You may also wish to make use of Tooltip

slopeExplorer[
   fn_, {x_, xmin_, xmax_}, {y_, ymin_, ymax_}] :=
  DynamicModule[{f, pta, ptb},
   f[t_] = fn /. x -> t;
   Manipulate[
    pta = {a, f[a]};
    ptb = {a, f'[a]};
    Show[
     Plot[{Tooltip[f[x]], Tooltip[f[a] + f'[a] (x - a)]},
      {x, xmin, xmax},
      PlotStyle -> {Blue, Orange},
      PlotRange -> {ymin, ymax},
      PlotLabel -> Row[{
         "Slope of tangent line =",
         Style[
          ToString[
            NumberForm[Round[f'[a], 0.01], {5, 2},
             NumberSigns -> {"-", " "},
             NumberPadding -> {" ", "0"}]] <> "\n",
          FontFamily -> "Courier", Bold]},
        Alignment -> {Center, Right}]],
     Plot[Tooltip[f'[x]], {x, xmin - 0.01, a},
      PlotStyle -> Directive[Red, Dashed]],
     Graphics[{Gray, Line[{pta, ptb}],
       Red, PointSize[Medium], Tooltip[Point[pta], pta],
       Blue, Tooltip[Point[ptb], ptb]}]],
    {{a, xmin, "x"}, xmin, xmax, Appearance -> "Labeled"}]];

slopeExplorer[2 x^3 - 3 x^2 - 36 x, {x, -5, 6}, {y, -150, 150}]
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • A definite essential addition. Students will also find this very helpful. Thanks for the tip. – David Jan 03 '16 at 21:09
3
slopeExplorer[fn_, {x_, xmin_, xmax_}, {y_, ymin_, ymax_}] := 
 DynamicModule[{f}, f[t_] = fn /. x -> t;
  Manipulate[Show[Plot[{f[x], f[a] + f'[a] (x - a)}, {x, xmin, xmax},
     PlotStyle -> {Directive[Blue], Directive[Orange]},
     PlotRange -> {ymin, ymax},
     PlotLabel -> 
      Pane["Slope of tangent line = " <> 
        ToString[PaddedForm[f'[a], {6, 2}]] <> "\n", 200]],
    Plot[f'[x], {x, xmin - 0.01, a},
     PlotStyle -> Directive[Red, Dashed]],
    Graphics[{Gray, Line[{{a, f[a]}, {a, f'[a]}}], Red, 
      PointSize[Medium], Point[{a, f[a]}], Blue, 
      Point[{a, f'[a]}]}]], {a, xmin, xmax}]]
slopeExplorer[2 x^3 - 3 x^2 - 36 x, {x, -5, 6}, {y, -150, 150}]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168