write a function to approximate the function f x using a taylor series
Using python to solve problem3 and problem4
Problem 3
Write a function to approximate the function, f(x), using a Taylor series. The Taylor series for the function, f(x), evaluated at x0 is given by the expression:
f(x) =
∞ X n=0
f(n)(x0) n!
(x−x0)n (9)
, however, we often truncate this inï¬nite sum at n = N and write the Taylor series as an approximation
f(x) ≈ PN(x) =
N X n=0
f(n)(x0) n!
(x−x0)n (10)
The function, f(x), can then be written as
f(x) = PN(x) + RN(x) (11)
By including more terms in the series, i.e., higher values of N, the truncation error reduces and the Taylor series becomes a better approximation for the function at x0. Demonstrate this by plotting the function RN(x) for different values of N for the following functions:
1. f(x) = ex at x0 = 0.
2. f(x) = 1 x2 at x0 = 4
Thanks