Lesson 12 of 18

Taylor Series Error

Taylor Series Error

The error of a degree-nn Taylor approximation is:

En(x)=f(x)Pn(x)E_n(x) = |f(x) - P_n(x)|

Taylor's Remainder Theorem

There exists some cc between aa and xx such that:

E_n(x) = rac{|f^{(n+1)}(c)|}{(n+1)!} cdot |x-a|^{n+1}

This bounds the error by the next term of the series (at the worst cc).

Intuition

  • The degree-nn polynomial matches ff through all derivatives up to order nn at aa
  • The first "mismatch" comes from the (n+1)(n+1)-th derivative
  • The further xx is from aa, the larger the error (raised to the n+1n+1 power)

Example: x3x^3 with P2P_2

For f(x)=x3f(x) = x^3, the Taylor polynomial at a=0a=0 with n=2n=2:

P_2(x) = f(0) + f'(0)x + rac{f''(0)}{2!} x^2 = 0 + 0 + 0 = 0

At x=2x=2: error =80== |8 - 0| = 8.

The bound from the theorem: rac{|f'''(c)|}{3!} cdot |2|^3 = rac{6}{6} cdot 8 = 8. Tight!

Convergence Check

For polynomial f(x)=xkf(x) = x^k, a Taylor polynomial of degree kk at a=0a=0 has zero error (it's exact).

Your Task

Implement double taylor_error(double (*f)(double), double a, double x, int n, double h) that returns f(x)Pn(x)|f(x) - P_n(x)|.

Helper functions from the Taylor polynomial lesson are provided.

TCC compiler loading...
Loading...
Click "Run" to execute your code.