I'm trying to do this:
In this graph, the secant points are aproximated in order to become the tangent, it seems I need some kind of function which plots a line based on two points and it's points do not limit the end of the line.
This is what I could do, as you can evaluate (see?), you'll see the line ends at the proposed points.
Show[{
Plot[{15 - 2 x^2}, {x, -1, 3}],
Graphics[Line[{{1, 13}, {2, 7}}]]
}]
I've read the reference on line but I still have no idea on how to do it, I imagine there are two ways of doing it, (1) the way I did, with Line
; (2) With the Plot
function.
Answer
A little bit more general (for any function, interval, starting and final points...) and implementing most of your labels:
appDeriv[f_, x0_, xinit_, pRange_List] := Module[{xseq, tan, tan1, l, plot, absPR},
xseq = Table[x0 + Exp[-n/2] (xinit - x0), {n, 0, 10}]; (* exploration points *)
tan = D[f@x, x] /. x -> x0; (* real derivative *)
tan1[x_] := (f[x] - f[x0])/(x - x0); (* approx derivative *)
l[t_] := Line[Transpose[{pRange, pRange t + (-t x0 + f@x0)}]]; (*line w/given angle*)
plot = Plot[f@x, {x, pRange[[1]], pRange[[2]]}, PlotStyle->Thick, PlotLabel->InputForm@f];
absPR = AbsoluteOptions[plot, PlotRange][[1, 2]]; (*get actual prange for the plot*)
Animate[Show[
plot,
Graphics[{
Thick, PointSize[Large],
Green, l[tan], Red, l[tan1[p]], Black, (* The two lines *)
Point[{x0, f@x0}],Point[{p,AbsoluteOptions[plot, AxesOrigin][[1,2,2]]}], Point[{p, f@p}],
Inset[ "x =" <> ToString@N@p, {p, (absPR[[2, 1]] 9 + absPR[[2, 2]])/10}],
Inset[Framed@Grid[{{"Exact ", tan}, {"Calculated", N@tan1[p]}}], {Left,Center},
{Left, Center}, Background -> Yellow]}]],
{p, xseq}] ];
GraphicsGrid[{{appDeriv[Sin@# + 1 &, 0, 2, {-2, 2}],appDeriv[2 # + 2 # # &, 1, 2, {-2, 2}]}}]
Comments
Post a Comment