f=expression(1/(1-x))
# First derivative
derv_1 <- D(f,'x')
Simplify(derv_1)
## 1/(1 - x)^2
derv_1_func <- function(x) {1/(1 - x)^2}
# Evaluate at zero
derv_1_func(0)
## [1] 1
# Second derivative
derv_2 <- D(D(f,'x'),'x')
Simplify(derv_2)
## 2/(1 - x)^3
derv_2_func <- function(x) {2/(1 - x)^3}
# Evaluate at zero
derv_2_func(0)
## [1] 2
# Third derivative
derv_3 <- D(D(D(f,'x'),'x'),'x')
Simplify(derv_3)
## 6/(1 - x)^4
derv_3_func <- function(x) {6/(1 - x)^4}
# Evaluate at zero
derv_3_func(0)
## [1] 6
# Fourth derivative
derv_4 <- D(D(D(D(f,'x'),'x'),'x'),'x')
Simplify(derv_4)
## 24/(1 - x)^5
derv_4_func <- function(x) {24/(1 - x)^5}
# Evaluate at zero
derv_4_func(0)
## [1] 24
# Fifth derivative
derv_5 <- D(D(D(D(D(f,'x'),'x'),'x'),'x'),'x')
Simplify(derv_5)
## 120/(1 - x)^6
derv_5_func <- function(x) {120/(1 - x)^6}
# Evaluate at zero
derv_5_func(0)
## [1] 120
We observe that the denominator, n!, yields the same result as the numerator:
factorial(1)
## [1] 1
factorial(2)
## [1] 2
factorial(3)
## [1] 6
factorial(4)
## [1] 24
factorial(5)
## [1] 120
Therefore, the Taylor Series simplifies to:
\(X^n\)
f=expression(e^x)
# First derivative
derv_1 <- D(f,'x')
Simplify(derv_1)
## e^x * log(e)
derv_1_func <- function(x) {exp(x)* log(exp(1))}
# Evaluate at zero
derv_1_func(0)
## [1] 1
# Second derivative
derv_2 <- D(D(f,'x'),'x')
Simplify(derv_2)
## e^x * log(e)^2
derv_2_func <- function(x) {exp(x) * log(exp(1))^2}
# Evaluate at zero
derv_2_func(0)
## [1] 1
# Third derivative
derv_3 <- D(D(D(f,'x'),'x'),'x')
Simplify(derv_3)
## e^x * log(e)^3
derv_3_func <- function(x) {exp(x) * log(exp(1))^3}
# Evaluate at zero
derv_3_func(0)
## [1] 1
# Fourth derivative
derv_4 <- D(D(D(D(f,'x'),'x'),'x'),'x')
Simplify(derv_4)
## e^x * log(e)^4
derv_4_func <- function(x) {exp(x) * log(exp(1))^4}
# Evaluate at zero
derv_4_func(0)
## [1] 1
# Fifth derivative
derv_5 <- D(D(D(D(D(f,'x'),'x'),'x'),'x'),'x')
Simplify(derv_5)
## e^x * log(e)^5
derv_5_func <- function(x) {exp(x) * log(exp(1))^5}
# Evaluate at zero
derv_5_func(0)
## [1] 1
Therefore, we see a polynomial approximation is:
sum((1/factorial(1)) + (1/factorial(2)) + (1/factorial(3)) + (1/factorial(4)) + (1/factorial(5)))
## [1] 1.716667
More formally, the Taylor Series can be represented as:
\(\sum_{n=0}^{\infty} \frac{x^n}{n!}\)
f=expression(log(1+x))
# First derivative
derv_1 <- D(f,'x')
Simplify(derv_1)
## 1/(1 + x)
derv_1_func <- function(x) {1/(1 + x)}
# Evaluate at zero
derv_1_func(0)
## [1] 1
# Second derivative
derv_2 <- D(D(f,'x'),'x')
Simplify(derv_2)
## -(1/(1 + x)^2)
derv_2_func <- function(x) {-(1/(1 + x)^2)}
# Evaluate at zero
derv_2_func(0)
## [1] -1
# Third derivative
derv_3 <- D(D(D(f,'x'),'x'),'x')
Simplify(derv_3)
## 2/(1 + x)^3
derv_3_func <- function(x) {2/(1 + x)^3}
# Evaluate at zero
derv_3_func(0)
## [1] 2
# Fourth derivative
derv_4 <- D(D(D(D(f,'x'),'x'),'x'),'x')
Simplify(derv_4)
## -(6/(1 + x)^4)
derv_4_func <- function(x) {-(6/(1 + x)^4)}
# Evaluate at zero
derv_4_func(0)
## [1] -6
# Fifth derivative
derv_5 <- D(D(D(D(D(f,'x'),'x'),'x'),'x'),'x')
Simplify(derv_5)
## 24/(1 + x)^5
derv_5_func <- function(x) {24/(1 + x)^5}
# Evaluate at zero
derv_5_func(0)
## [1] 24
Therefore, we see a polynomial approximation is:
sum((1/factorial(1)) + (-1/factorial(2)) + (2/factorial(3)) + (-6/factorial(4)) + (24/factorial(5)))
## [1] 0.7833333
The approximation can also be written as:
\(0 + \frac{1}{1!}x - \frac{1}{2!}x^2 + \frac{2}{3!}x^3 - \frac{6}{4!}x^3\)
More formally, the Taylor Series can be represented as:
\(\sum_{n=1}^{\infty} -1^{n+1} \frac{x^n}{n}\)