381 - A8 - Taylor's

358 days ago by Professor381

f = 1/x a = 1 fp = f.derivative() fpp = fp.derivative() fppp = fpp.derivative() G = plot(f,(x,0.2,5),color='red',thickness='5') + point((a,f(x=a)),size=50,color='red') p1= f(x=a) + fp(x=a)*(x-a) G += plot(p1,(x,0.2,5),color='blue') p2 = f(x=a) + fp(x=a)*(x-a) + fpp(x=a)*(x-a)^2/2 G += plot(p2,(x,0.2,4),color='green') p3 = p2 + fppp(x=a)*(x-a)^3/6 G += plot(p3,(x,0.2,3),color='orange') show(G) 
       
# what about piecewise? f = 1/x G = plot(f,(x,0.2,5),color='red') x1 = 1 x2 = 2 x3 = 3 x4 = 5 p1 = (x-x2)/(x1-x2)*f(x=x1) + (x-x1)/(x2-x1)*f(x=x2) G += plot(p1,(x,x1,x2),color='blue') p2 = (x-x3)/(x2-x3)*f(x=x2) + (x-x2)/(x3-x2)*f(x=x3) G += plot(p2,(x,x2,x3),color='blue') p3 = (x-x4)/(x3-x4)*f(x=x3) + (x-x3)/(x4-x3)*f(x=x4) G += plot(p3,(x,x3,x4),color='blue') show(G)