I need to write a display function of Taylor formula, the following code
The import sympy as sy
The import numpy as np
The from sympy. Functions provides the import sine, cosine
# Define the variable and the function to approximate
X=sy. Symbol (' x ')
# the Factorial function
Def factorial (n) :
If n & lt;=0:
Return 1
The else:
Return the factorial n * (n - 1)
# Taylor approximation at x0 of the function 'function'
Def Taylor (function, x0, n) :
I=0
P=0
For I in range (0, n + 1) :
P=p + (function. The diff (x, I). Subs (x, x0))/(the factorial (I)) * * * (x - x0) I
The return p
* * 3 filling operation such as input Taylor (x), the result is
27 * x + (x - 3) 3 + 9 * * * * * 2 - (x - 3) 54
Not the right answer
27 + 27 (x - 3) * x + 9 * * * 2 + (x - 3) * * 3
Bosses, please have a look at the code where I went wrong, thank you very much!!!!!