For this discussion post, I’ve chosen to demonstrate how a problem from the homework can be solved using R.

Page 496 Problem 5

Key Idea 8.8.1 gives the nth term of the Taylor series of common funcƟons. In Exercises 3 – 6, verify the formula given in the Key Idea by finding the first few terms of the Taylor series of the given funcƟon and identifying a pattern.

  1. \(f(x)=1/(1-x); c = 0\)

Solution

This was problem 1 from the homework. My work on the homework is shown here:

HW 14 Problem 1

If \(f(x)=\frac{1}{1-x}\), then…

\(f'(x)=(-1)(1-x)^{-2}(-1)=(-1)^2(1-x)^{-2}\\f''(x)=(-2)(-1)^2(1-x)^{-3}(-1)=(2)(-1)^4(1-x)^{-3}\\f'''(x)=(-3)(2)(-1)^4(1-x)^{-4}(-1)=(3)(2)(-1)^6(1-x)^{-4}\\f''''(x)=(-4)(3)(2)(-1)^6(1-x)^{-5}(-1)=(4)(3)(2)(-1)^8(1-x)^{-5}\)

We can see from this pattern that the \(n\)th derivative of \(f(x)\), \(f^{(n)}(x)\), will be \(f^{(n)}(x)=n!(-1)^{2n}(1-x)^{-n-1}=n!(1-x)^{-n-1}\)

When \(x=0\), \(f^{(n)}(x)=n!\) since \((1-0)^{-n-1}\) must be 1, and this results in the following expansion:

\(1+\frac{1!}{1!}x+\frac{2!}{2!}x^2+\frac{3!}{3!}x^3+...\\=1+x+x^2+x^3+...\)

Therefore, the Taylor Series expansion of \(f(x)=\frac{1}{1-x}\) is \(\sum\limits_{n=0}^\infty x^n\)

Replicating the Solution With R

We can use the “taylor” function from the “calculus” library to attempt to replicate our solution.

library(calculus)
f_x <- function(x) { 1 / (1 - x) }

taylor(f_x, 0, order = 4)
## $f
## [1] "(1) * 1 + (0.999999999999872) * x1^1 + (0.999999999868096) * x1^2 + (0.999994567806407) * x1^3 + (0.999693345452476) * x1^4"
## 
## $order
## [1] 4
## 
## $terms
##    var      coef degree
## 0    1 1.0000000      0
## 1 x1^1 1.0000000      1
## 2 x1^2 1.0000000      2
## 3 x1^3 0.9999946      3
## 4 x1^4 0.9996933      4

We see the coefficients deviating from 1 by a small amount starting with the fourth term, but this is expected since the Taylor Series is an approximation of the function. The coefficients are sufficiently close to 1 to confirm our solution.