#範例10-6:以泰勒多項式逼近sin(x)函數 from sympy import * x = symbols('x') f = Function('f')(x) f = sin(x) ty1 = series(f, x, x0=0, n=24).removeO() ty2 = series(f, x, x0=0, n=25).removeO() ty3 = series(f, x, x0=0, n=26).removeO() #畫圖 p1 = plot(f, ty1, ty2, ty3, (x, -10, 10), show='False') p1[0].line_color= 'red' p1[1].line_color= 'blue' p1[2].line_color= 'green' p1[3].line_color= 'yellow' p1[0].label= '$sin(x)$' p1[1].label= '$taylor(n=23)$' p1[2].label= '$taylor(n=24)$' p1[3].label= '$taylor(n=25)$' p1.legend = True p1.show()