code for diagrams
> tanapprx := proc (f, w, deltax, range ) local P1, P2, pointsplot, line1, line2, line3, line4, fplot, fw, chordplot, tanslope, tanline, tanplot, txt1, txt2, line5, line6, putfx, putfxplush, putx, puth, putp2, putdeltax, putdeltay; P1 := [w, subs(x = w,f)]; P2 := [w+deltax, subs(x = w+deltax,f)]; pointsplot := plot({P1, P2},style = POINT,thickness = 3,color = black); line1 := plot([[P1[1], 0], P1],linestyle = 3); line2 := plot([P1, [0, P1[2]]],linestyle = 3); line3 := plot([[P2[1], 0], P2],linestyle = 3); line4 := plot([P2, [0, P2[2]]],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 = range[1] .. range[2],color = black); txt2 := plots[textplot]([range[2], subs(x = range[2],tanline), ` TANGENT`],align = RIGHT,color = brown); line5 := plot([[P2[1], P1[2]], P1],linestyle = 1,thickness = 2); line6 := plot([[P2[1], P1[2]], P2],linestyle = 1,thickness = 2); putfx := plots[textplot]([1, P1[2], `f(x)`],align = LEFT,font = [TIMES, BOLD, 14]); putfxplush := plots[textplot]([1, P2[2], `f(x+h)`],align = LEFT,font = [TIMES, BOLD, 14]); putx := plots[textplot]([P1[1], 0, x],align = BELOW,font = [TIMES, BOLD, 14]); puth := plots[textplot]([P2[1], 0, ` x+h `],align = BELOW,font = [TIMES, BOLD, 14]); putp2 := plots[textplot]([P2[1], 1.1*P2[2], `( x+h, f(x+h)+f'(x)h )`],align = LEFT,font = [TIMES, BOLD, 14]); putdeltax := plots[textplot]([.5*P1[1]+.5*P2[1], P1[2], `Delta x = h`],align = BELOW,font = [TIMES, BOLD, 14]); putdeltay := plots[textplot]([P2[1], .5*P1[2]+.5*P2[2], `Delta y`],align = RIGHT,font = [TIMES, BOLD, 14]); plots[display]([pointsplot, putfx, putfxplush, putx, puth, putdeltax, putdeltay, putp2, txt2, fplot, tanplot, line1, line2, line3, line4, line5, line6],scaling = constrained,title = `Tangent line approximaton`,xtickmarks = [0],ytickmarks = [],titlefont = [TIMES, BOLD, 18],axesfont = [TIMES, BOLD, 16]) end:
> f:=2+sin(x+3):
> tanapprx(f,3.5,1,[1,5],[0,9]);