Frustration.
I'm trying to do a Mean Value Theorem demonstration, where two points can be selected on a curve, and the computer will find the point(s) at which the derivative matches the average slope, and display that point plus the tangent line.
All was going well, and then I hit the following snag. In the code below I've defined the variables I need (I think), and the secant line displays just fine. However, I can't get the program to actually COMPUTE the value of m1. All it does is substitute values into the difference quotient (for lack of a better term) without actually finding the numerical value. Drag the points around and check out the value of m1 below the plot.
I'm sure I'm doing something incorrectly -- I just need someone to tell me what it is.
Thanks, as always. Code is below.
Rob
_________________
Clear[f];
f[x_] := x^2;
dpt1 = {0, 1};
dpt2 = {1, 0};
x1 = Dynamic[First[dpt1]];
y1 = Dynamic[f[First[dpt1]]];
x2 = Dynamic[First[dpt2]];
y2 = Dynamic[f[x2]];
m1 = (y2 - y1)/(x2 - x1);
xx1 = Dynamic[Solve[D[f[x], x] == m1, x]];
tangentPlot =
Plot[m1*(x - xx1) + f[xx1], {x, -2, 2}, PlotStyle -> Green];
LocatorPane[
Dynamic[{dpt1, dpt2}],
Show[{
Plot[f[x], {x, -2, 2}],
tangentPlot,
Graphics[{
Red, Line[{
Dynamic[{x1, y1}], Dynamic[{x2, y2}]
}]
}]
},
Epilog -> {PointSize[Large], Point[Dynamic[{x1, y1}]],
Point[Dynamic[{x2, y2}]]}
],
Appearance -> None
]
__________
Also, just beneath this line, put a line that just says "m1", and enter that. then you can hopefully see the behavior of m1 that I'm talking about...

