Chapter 8.8 - Exercise 13

In Exercises 13–16, show that the Taylor series for \(f(x)\), as given in Key Idea 8.8.1, is equal to \(f(x)\) by applying Theorem 8.8.1; that is, show \[ \lim_{n \to \infty} R_n(x) = 0. \]

  1. \(f(x) = e^x\)
# e^x calculation using Taylor series
taylor_series_ex <- function(x, n) {
  sum <- 0
  for (k in 0:n) {
    sum <- sum + (x^k) / factorial(k)
  }
  return(sum)
}

# example
x <- 1
terms <- 20  # Number of terms in the Taylor series

actual_ex <- exp(x)
approx_ex <- taylor_series_ex(x, terms)

cat("Actual e^x:", actual_ex, "\n")
## Actual e^x: 2.718282
cat("Taylor Series Approximation of e^x:", approx_ex, "\n")
## Taylor Series Approximation of e^x: 2.718282
cat("Difference:", abs(actual_ex - approx_ex), "\n")
## Difference: 4.440892e-16

The number results from R show that the Taylor series approximation for \(e^x\) gets really close to the actual value, even when we just use a limited number of terms. As \(n\) goes up, the error between the real value and the approximation almost becomes nothing. This proves how the Taylor series can reach the exact function \(e^x\) as expected by theory.