<<

The Relationship Between the Secant and the Lines

Initialization > restart: with(plots): with(plottools): Warning, the name changecoords has been redefined

Motivation by a simple example Consider a simple quadratic function > f := x -> x^2; f := x ® x 2 with the following graph > plot(f(x),x=-2..2);

The is easy to compute > diff(f(x),x); 2 x and at the x=1, we find the > subs(x=1,%); 2 and compute the tangent at x=1 > T := x -> f(1) + 2*(x-1); T := x ® f(1) + 2 x - 2 We can plot the tangent > plot(T(x),x=-2..2);

and plot both functions on the same graph... > plot({f(x),T(x)},x=-2..2); Now a more general example Define f(x) to be any function you want (as long as it has a derivative!) > f := x -> sin(x); f := sin Let a be point of tangency > a := 1.0; a := 1.0 Find the derivative of f(x), call it Df(x) > Df := unapply( diff(f(x),x) , x ); Df := cos > m := evalf(Df(a)); m := .5403023059 Find the equation of the tangent line at the point x=a > T := x -> evalf(f(a))+m*(x-a); T := x ® evalf(f(a)) + m (x - a) Let d determine the size of the region around the point of tangency > d := 1.0; d := 1.0 and plot the function and the tange line > plot({f(x),T(x)},x=a-d..a+d, y=f(a)-d..f(a)+d); We can "zoom" in on the point of tangency Set the size of the plot region > d := 10: plot the function, tangent line, and the point of tangency. Each time the following is executed, the window reduces in size allowing us to zoom in. Notice the graphs approach straight lines... > fplot := plot(f(x), x=a-d..a+d, y=f(a)-d..f(a)+d, color=red): Tplot := plot(T(x), x=a-d..a+d, y=f(a)-d..f(a)+d, color=blue): Cplot := ([a,f(a)],d/50,color=green): display({fplot,Tplot,Cplot}); d := d/2.0: Define a function to do the zooming for us ... zoom( ) will depend on the function, as well as the point of tangency, and the size of the window. > zoom := proc(f,a,d) local m, Df, T, fplot, Tplot, Cplot,x; Df := unapply( diff(f(x),x) , x ); m := evalf(Df(a)); T := x -> evalf(f(a))+m*(x-a); fplot := plot(f(x), x=a-d..a+d, y=f(a)-d..f(a)+d, color=red): Tplot := plot(T(x), x=a-d..a+d, y=f(a)-d..f(a)+d, color=blue): Cplot := circle([a,f(a)],d/50,color=green): display({fplot,Tplot,Cplot}); end: We must define the function as a "rule" > d := 4.0; d := 4.0 > f := x -> sin(x): zoom(f,2,d); d := d/2.0; d := 2.000000000 > Define a "slide" function Plot the tangent line as a function of the point of tangency, and the end points of the intervals > slide := proc(f,a,b,c) local m, d, Df, T, fplot, Tplot, Cplot, x; d := c-b; Df := unapply( diff(f(x),x) , x ); m := evalf(Df(a)); T := x -> evalf(f(a))+m*(x-a); fplot := plot(f(x), x=b..c, color=red): Tplot := plot(T(x), x=b..c, color=blue): Cplot := circle([a,f(a)],d/40,color=black): display({fplot,Tplot,Cplot}); end: Set up the parameters > b := -5.0: c := 5.0: N := 20: dx := (c-b)/N: Go forwards and backwards along the function > for i from 0 to N-1 do p[i] := slide(f,b+i*dx,b,c): od: for i from N to 2*N do p[i] := slide(f,c+(N-i)*dx,b,c): od: Create an animated sequence of plots ... > display(seq(p[i],i=0..2*N),insequence=true);

> Watch the secant approach the tangent Plot the secant line as a function of the point, the approaching point, and the endpoints of the > secant := proc(f,a,b,c,d) local Df, mS, mT, S, T, Cplot1, Cplot2, fplot, Splot, Tplot, x; mS := (f(b)-f(a))/(b-a); S := x -> f(a) + mS*(x-a); Df := unapply( diff(f(x),x) , x ); mT := evalf(Df(a)); T := x -> evalf(f(a))+mT*(x-a); fplot := plot(f(x), x=c..d, color=red): Splot := plot(S(x), x=c..d, color=blue); Tplot := plot(T(x), x=c..d, color=black); Cplot1 := circle([a,f(a)],(d-c)/100,color=black); Cplot2 := circle([b,f(b)],(d-c)/100,color=black); display({fplot,Splot,Tplot,Cplot1,Cplot2}); end: Create a sequence of plots approaching the tangent point > for i from 0 to 20 do p[i] := secant(f,0,-2+i*0.1,-4,4): od: Now animate the sequence > display(seq(p[i],i=0..20),insequence=true);