This week, we’ll work out some Taylor Series expansions of popular functions.

\(f(x) = \frac{1}{(1-x)}\)

\(f(x) = e^x\)

\(f(x) = ln(1+x)\)

For each function, only consider its valid ranges as indicated in the notes when you are computing the Taylor Series expansion. Please submit your assignment as a R-Markdown document.

The formula for Taylor Polynomial is:

\[f(x) \approx \sum_{n=0}^{\infty} \frac{f^{(n)} (a)}{n!} (x-a)^n\]

Equation 1

Derivation

The first three derivatives for \(f(x) = \frac{1}{1-x}\) are \[f'(x) = \frac{1}{(1-x)^2} \\ f''(x) = \frac{2}{(1-x)^3} \\ f'''(x) = \frac{6}{(1-x)^4}\]

This can be generalized as \[f^{(n)}(x) = \frac{n!}{(1-x)^{n+1}}\]

Substituting this into the general equation, \[\frac{1}{1-x} \approx \sum_{n=0}^{\infty} \frac{n!}{(1-a)^{n+1}} \times \frac{(x-a)^n}{n!} = \frac{(x-a)^n}{(1-a)^n}\]

At \(a=0\), this becomes \[\frac{1}{1-x} \approx \sum_{n=0}^{\infty} x^n\]

Convergence

Using the ratio series for infinite series: \[\frac{A_{n+1}}{A_n} = \frac{x^{n+1}}{x^n} = x \\ \lim_{n \to \infty} x = x\]

So the series converges for \(|x| < 1\).

Validation

The true values and series approximations are plotted for \(n=25\):

taylor1 <- function(x, n) {
  sum <- 0
  for(i in 0:n) {
    sum <- sum + x^i
  }
  sum
}

It can be seen in the plot above that there is some divergence between the function and its Taylor series approximation at the edges of the range (-1, 1).

Equation 2

Derivation

The derivative of \(f(x) = e^x\) is \(e^x\), so any derivative \(f^{(n)}(x) = e^x\).

Substituting this into the general equation,

\[e^x \approx \sum_{n=0}^{\infty} e^x \times \frac{(x-a)^n}{n!} = \frac{e^x (x-a)^n}{n! (1-a)^n}\]

At \(a=0\), this becomes \[\frac{1}{1-x} \approx \sum_{n=0}^{\infty} \frac{x^n}{n!}\]

Convergence

Using the ratio series for infinite series: \[\frac{A_{n+1}}{A_n} = \frac{x^{n+1}}{(n+1)!} \frac{n!}{x^n} = \frac{x}{n+1} \\ \lim_{n \to \infty} \frac{x}{n+1} = 0\]

So the series converges for all values of x.

Validation

The true values and series approximations are plotted for \(n=25\):

taylor2 <- function(x, n) {
  sum <- 0
  for(i in 0:n) {
    sum <- sum + x^i / factorial(i)
  }
  sum
}

It can be seen in the plot above that the function and its taylor series approximation entirely overlap.

Equation 3

Derivation

The first four derivatives for \(f(x) = \ln(x)\) are \[f^{(1)}(x) = \frac{1}{1+x} \\ f^{(2)}(x) = \frac{-1}{(1+x)^2} \\ f^{(3)}(x) = \frac{2}{(1+x)^3} \\ f^{(4)}(x) = \frac{-6}{(1+x)^4}\]

This can be generalized as \[f^{(n)}(x) = (-1)^{n-1} \frac{(n-1)!}{(1+x)^{n}}\]

Substituting this into the general equation, \[\ln(1+x) \approx \sum_{n=0}^{\infty} (-1)^{n-1} \frac{(n-1)!}{(1+a)^{n}} \times \frac{(x-a)^n}{n!} = (-1)^{n-1} \frac{(x-a)^n}{n (1+a)^n}\]

At \(a=0\), this becomes \[\ln(1+x) \approx \sum_{n=0}^{\infty} (-1)^{n-1} \frac{x^n}{n}\]

Convergence

Using the ratio series for infinite series: \[\frac{A_{n+1}}{A_n} = - \frac{x^{n+1}}{n} \frac{n}{x^n} = - \frac{-xn}{n+1} \\ \lim_{n \to \infty} \frac{-xn}{n+1} = -x\]

So the series converges for \(|x| < 1\).

Validation

The true values and series approximations are plotted for \(n=25\):

taylor3 <- function(x, n) {
  sum <- 0
  for(i in 1:n) { # starting at n=1 since n=0 causes Inf
    sum <- sum + (-1)^(i + 1) * x^i / i
  }
  sum
}

As in the first plot, there is some divergence between the function and its Taylor series approximation at the lower edge of the valid range near -1.