code for diagrams
look4 inputs an expression f, points w1, w2 and an interval range=[a,b]. It returns the graph of y=f(x) on the range with the tsngent line to f at w1 and the point (w2,f(w)) indicated for comparision.
> look4:=proc (f, w1,w2, range) local y, P1, P2, titl, pointsplot, line1, line2, line3, line4, fplot, fw, chordslope, chord, chordplot, tanslope, tanline, tanplot, txt1, txt2;titl:= tangent_at_x : P1 := [w1, subs(x = w1,f)]; P2 := [w2, subs(x = w2,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,thickness=3); fw := subs(x = w1,f); tanslope := subs(x = w1,diff(f,x)); tanline := (x-P1[1])*tanslope+P1[2]; tanplot := plot(tanline,x = range[1] .. range[2],color = black); txt1 := plots[textplot]([.85*range[2], subs(x = .8*range[2],tanline), convert(titl = w1,string)],align = RIGHT,color = brown); plots[display]([pointsplot, txt1, fplot, tanplot, line1, line2, line3, line4], title = convert(y = f ,string), titlefont = [TIMES, BOLD, 18],axesfont = [TIMES, BOLD, 12],xtickmarks=[0,w1/2,w1,w2,range[1],range[2]]) end:
> look4(x^2,1,1.1,[0,2]); look4(x^2,1,1.1,[.95,1.2]);