Any function that is infinitely differentiable can be represented by a polynomial of the following form:

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

where \(f^{n}(a)\) represents the \(nth\) derivative of \(f(x)\) evaluated at \(x = a\).

Problem 1

\[f(x) = \frac{1}{1-x}, x\in(-1, 1)\] \[= \sum_{n=0}^\infty x^{n}, x\in(-1, 1)\]

\[= 1 + x + x^{2} + x^{3} + x^{4} + x^{5} +...\]

library(ggplot2)

p <- ggplot(data = data.frame(x=0), mapping = aes(x = x))
fun.1 <- function(x) 1/(1-x)
taylor.1 <- function(x) 1 + x + x^2 + x^3 + x^4 + x^5

p + 
  layer(stat = "function", 
    fun = fun.1, 
    mapping = aes(color = "fun.1"),
    position = "jitter"
    ) + 
  layer(stat = "function", 
    fun = taylor.1, 
    mapping = aes(color = "taylor.1")
    ) + 
  scale_x_continuous(limits = c(-1, 1)) +
  scale_color_manual(name = "Functions", 
                     values = c("blue", "red"),
                     labels = c("1/(1-x)", "Taylor Series Approximation (5th order)"))

Problem 2

\[f(x) = e^x\] \[= \sum_{n=0}^\infty \frac{x^{n}}{n!}, x\in(-1, 1)\]

\[= 1 + x + \frac{x^{2}}{2} + \frac{x^{3}}{6} + \frac{x^{4}}{24} + \frac{x^{5}}{120} +...\]

p <- ggplot(data = data.frame(x=0), mapping = aes(x = x))
fun.2 <- function(x) exp(x)
taylor.2 <- function(x) x^0/factorial(0) + x^1/factorial(1) + x^2/factorial(2) + x^3/factorial(3) + x^4/factorial(4) + x^5/factorial(5)

p + 
  layer(stat = "function", 
    fun = fun.2, 
    mapping = aes(color = "fun.2"),
    position = "jitter"
    ) + 
  layer(stat = "function", 
    fun = taylor.2, 
    mapping = aes(color = "taylor.2")
    ) + 
  scale_x_continuous(limits = c(-1, 1)) +
  scale_color_manual(name = "Functions", 
            values = c("blue", "red"),
            labels = c("e^x", "Taylor Series Approximation (5th order)"))

Problem 3

\[f(x) = ln(1 + x)\] \[= \sum_{n=0}^\infty (-1)^{n+1}\frac{x^{n}}{n}, x\in(-1, 1)\]

\[= x - \frac{x^{2}}{2} + \frac{x^{3}}{3} - \frac{x^{4}}{4} + \frac{x^{5}}{5} -...\]

p <- ggplot(data = data.frame(x=0), mapping = aes(x = x))
fun.3 <- function(x) log(1+x)
taylor.3 <- function(x) x - (x^2/2) + (x^3/3) - (x^4/4) + (x^5/5)

p + 
  layer(stat = "function", 
    fun = fun.3, 
    mapping = aes(color = "fun.3"),
    position = "jitter"
    ) + 
  layer(stat = "function", 
    fun = taylor.3, 
    mapping = aes(color = "taylor.3")
    ) + 
  scale_x_continuous(limits = c(-1, 1)) +
  scale_color_manual(name = "Functions", 
            values = c("blue", "red"),
            labels = c("log(1+x)", "Taylor Series Approximation (5th order)"))