Elina Azrilyan

November 27th, 2019

ASSIGNMENT 14 - TAYLOR SERIES

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

• f(x) = 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.

Soluiton: we will set c=0 and use the following equation.

knitr::include_graphics("881.png")

Function 1

f(x) = 1 / (1−x)

We will find the value of the 5 derivatives of this function at 0.

#First Derivative
x<-0
f=expression(1/(1-x))
eval(f)
## [1] 1
f<-D(f,'x')
eval(f)
## [1] 1
#Second Derivative
f<-D(f,'x')
eval(f)
## [1] 2
#Third Derivative
f<-D(f,'x')
eval(f)
## [1] 6
#Forth Derivative
f<-D(f,'x')
eval(f)
## [1] 24
#Fifth Derivative
f<-D(f,'x')
eval(f)
## [1] 120
Answer: 1x^0 + 1x^1 + (2 / 2!)x^2 + (6 / 3!)x^3 + (24 / 4!)x^4 + 120 / 5!)x^5

Simplifying this expression gives us:

1 + x + x^2 + x^3 + x^4 + x^5 + …

Verification using Taylor function:
library(pracma)
## Warning: package 'pracma' was built under R version 3.5.2
x = function(x) {1 / (1-x) }
c = 0
taylor(x, c, 5)
## [1] 1.000293 1.000029 1.000003 1.000000 1.000000 1.000000

Function 2

f(x) = e^x

We will find the value of the 5 derivatives of this function at 0.

#First Derivative
x<-0
f=expression(exp(x))
eval(f)
## [1] 1
f<-D(f,'x')
eval(f)
## [1] 1
#Second Derivative
f<-D(f,'x')
eval(f)
## [1] 1
#Third Derivative
f<-D(f,'x')
eval(f)
## [1] 1
#Forth Derivative
f<-D(f,'x')
eval(f)
## [1] 1
#Fifth Derivative
f<-D(f,'x')
eval(f)
## [1] 1
Answer: 1x^0 + 1x^1 + (1 / 2!)x^2 + (1 / 3!)x^3 + (1 / 4!)x^4 + 1 / 5!)x^5

Simplifying this expression gives us:

1 + x + (x^2) / 2 + (x^3) / 6 + (x^4) / 24 + (x^5) / 120 + …

Verification using Taylor function:
library(pracma)

x = function(x) {exp(x)}
c = 0
taylor(x, c, 5)
## [1] 0.008334245 0.041666573 0.166666726 0.499999996 1.000000000 1.000000000

Function 3

f(x) = ln(1+x)

We will find the value of the 5 derivatives of this function at 0.

#First Derivative
x<-0
f=expression(log(1+x))
eval(f)
## [1] 0
f<-D(f,'x')
eval(f)
## [1] 1
#Second Derivative
f<-D(f,'x')
eval(f)
## [1] -1
#Third Derivative
f<-D(f,'x')
eval(f)
## [1] 2
#Forth Derivative
f<-D(f,'x')
eval(f)
## [1] -6
#Fifth Derivative
f<-D(f,'x')
eval(f)
## [1] 24
Answer: 0x^0 + 1x^1 + (-1 / 2!)x^2 + (2 / 3!)x^3 + (-6 / 4!)x^4 + 24 / 5!)x^5

Simplifying this expression gives us:

x - (x^2) / 2 + (x^3) / 3 - (x^4) / 4 + (x^5) / 5 + …

Verification using Taylor function:
library(pracma)

x = function(x) {log(1+x)}
c = 0
taylor(x, c, 5)
## [1]  0.2000413 -0.2500044  0.3333339 -0.5000000  1.0000000  0.0000000