# Set PlotLabel length

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?

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}] • Absolutely perfect! Great answer. Thanks for the help. This will keep the students' eyes from blinking when they use this demonstration. – David Jan 3 '16 at 20:25
• Try slopeExplorer[(1 - x)/(2 + x), {x, -4, 3}, {y, -20, 20}]. I think the title thinks it has an exact slope number until your start moving the slider. I found that this cures the problem: PaddedForm[N[f'[a]], {6, 2}]]. Recommend edit to your code. – David Jan 3 '16 at 22:04
• Try this example: slopeExplorer[Sqrt[x - 1], {x, 1.0001, 5}, {y, 0, 5}]. What happens is the beginning part of the dashed derivative curve begins to disappear as the slider moves to the right. Turns out this fixed this problem: Plot[f'[x], {x, xmin - 0.01, a}, PlotRange -> All, – David Jan 3 '16 at 22:16
• Turns out my previous comment caused a problem. See: Some time difficulty in a Manipulate program inside a DynamicModule. So don't use PlotRange->All. The best version of this demonstration code that now exists is on Some time difficulty in a Manipulate program inside a DynamicModule. See Bob Hanlon's answer. – David Jan 4 '16 at 5:10

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}]

• A definite essential addition. Students will also find this very helpful. Thanks for the tip. – David Jan 3 '16 at 21:09