(*Module封装外部函数*)
DynamicModule[{pts = {{1, 1}, {2, 8}, {3, 27}}},
LocatorPane[Dynamic[pts, (pts = {#1, #1^3} & @@@ #) &],
Dynamic@Module[{line},
line[p1_, p2_] :=
Module[{tmp = p2 - p1, inc = 100.},
Line[{p1 + inc*tmp, p2 - inc*tmp}]];
Show[Plot[x^3, {x, -5, 5}, PlotStyle -> {Thick, Black}],
Graphics[MapThread[line, Partition[pts, 2, 1]]],(*过3点至导函数竖线*)
Graphics[{Dashing[{0.03, 0.010}], Red, Opacity[0.7],
Thickness[0.005],
Line[{{pts[[3, 1]],
pts[[2, 2]]}, {pts[[3,
1]], (6 pts[[2, 1]] (pts[[3, 1]] - pts[[2, 1]])^2 +
pts[[2, 2]])}}]}],(*过2点横线*)
Graphics[{Dashing[{0.015, 0.010}], Red, Thickness[0.005],
Line[{pts[[2]], {pts[[3, 1]], pts[[2, 2]]}}]}],
(*过3点竖线*)
Graphics[{Dashed, Blue, Thickness[0.008],
Line[{pts[[
3]], {pts[[3,
1]], (pts[[2, 2]] - pts[[1, 2]])/(
pts[[2, 1]] - pts[[1, 1]]) (pts[[3, 1]] - pts[[1, 1]]) +
pts[[1, 2]]}}]}],(*过2点一阶导函数*)
Plot[(6 pts[[2, 1]] (x - pts[[2, 1]])^2 + pts[[2, 2]]), {x, -10,
10},
PlotStyle -> {Dashing[{0.005, 0.008}], Thickness[0.005],
GrayLevel[0.68]}], PlotRange -> {{-5, 5}, {-5, 30}},
ImageSize -> 500]]]]