code for diagrams
look2 inouts an expression f in the varaible x, a point w in the range = [a,b] and the length of the tangent segments
>
look2:=proc (f, w, linelength,range) local P1, pointsplot, fplot, fw, chordslope,line1, tanslope, tanline, tanplot; fw:=subs(x=w,f);
P1:= [w, fw];
pointsplot:= plot( {P1, [P1[1],0]},style = POINT,thickness = 3,color = black); line1 := plot([[P1[1], 0], P1],linestyle = 3);
fplot := plot(f,x = range[1] .. range[2],thickness = 1,color = blue); fw := subs(x = w,f); tanslope := subs(x = w,diff(f,x)); tanline := (x-P1[1])*tanslope+P1[2]; tanplot := plot(tanline,x = w-linelength.. w+linelength,color = black); plots[display]([line1,pointsplot, fplot, tanplot],scaling = constrained,title = `Tangent Line Segment(s)` ,xtickmarks = [0,w],ytickmarks = [0],titlefont = [TIMES, BOLD, 18],axesfont = [TIMES, BOLD, 16]) end:
look3 inputs an expression, f in the variable x, a list w of points, the length one wants the tangent line segments, and a range = [a,b] over which the plot is made
>
look3:=proc (f, w, linelength,range) local P1, pointsplot,i, fplot, fw, z,chordslope,line1, tanslope, tanline, tanplot; fw:=[seq(subs(x=z,f),z=w)];
P1:= [seq([w[i], fw[i]],i=1..nops(w))];
pointsplot:=[seq( plot( {z, [z[1],0]},style = POINT,thickness = 3,color = black),z=P1)]; line1 := [seq(plot([[z[1], 0], z],linestyle = 3),z=P1)];
fplot := plot(f,x = range[1] .. range[2],thickness = 1,color = blue); fw := subs(x = w,f); tanslope := [seq(subs(x = z,diff(f,x)),z=w)]; tanline := [seq((x-P1[i][1])*tanslope[i]+P1[i][2],i=1..nops(w))];
tanplot := [seq( plot(tanline[i],x = w[i]-linelength..w[i]+linelength, color = black) , i=1..nops(w))];
plots[display](tanplot); plots[display]([op(line1),op(pointsplot),op(tanplot), fplot ],scaling = constrained,title = `Tangent Line Segment(s)` ,xtickmarks = [0,op(w)],ytickmarks = [0],titlefont = [TIMES, BOLD, 18],axesfont = [TIMES, BOLD, 16]) end:
> look3(sqrt(25^2-x^2),[7,12,20],10,[-30,30]);