For each function, only consider its valid ranges as indicated in the notes when you are computing the Taylor Series expansion.
Answers: a) \(f(x) = \frac{1}{1-x}\)
We can use pracma library for the Taylor series expansion but in this case we’ll make a function for the derivations:
taylor_expansion <- function(f) {
print(f)
x <- 0
coef <- eval(f) / factorial(0)
print(paste0(coef , 'x'))
for (n in 1:5) {
f <- D(f,'x')
eval_f <- eval(f)
factorial_n <- factorial(n)
coef <- round(eval(f) / factorial(n), 3)
print(paste0(coef,'*x^', n))
}
}
For \(f(x) = \frac{1}{1-x}\):
f=expression( 1/(1-x) )
taylor_expansion(f)
## expression(1/(1 - x))
## [1] "1x"
## [1] "1*x^1"
## [1] "1*x^2"
## [1] "1*x^3"
## [1] "1*x^4"
## [1] "1*x^5"
So:
\(\sum_{n=0}^{\inf} \frac{f^n(c)}{n!}(x-c)^n\) where \(f(x) = \frac{1}{1-x}\) and c = 0:
\(\sum_{n=0}^{\inf} \frac{f^n(c)}{n!}(x-c)^n = x + x + x^2 + x^3 + x^4 + x^5 +...\)
b) \(f(x) = e^x\)
f=expression(exp(x))
taylor_expansion(f)
## expression(exp(x))
## [1] "1x"
## [1] "1*x^1"
## [1] "0.5*x^2"
## [1] "0.167*x^3"
## [1] "0.042*x^4"
## [1] "0.008*x^5"
\(\sum_{n=0}^{\inf} \frac{f^n(c)}{n!}(x-c)^n = x + x + 0.5x^2 + 0.167x^3 + 0.042x^4 + 0.008x^5 +...\)
f=expression(log(1+x))
taylor_expansion(f)
## expression(log(1 + x))
## [1] "0x"
## [1] "1*x^1"
## [1] "-0.5*x^2"
## [1] "0.333*x^3"
## [1] "-0.25*x^4"
## [1] "0.2*x^5"
\(\sum_{n=0}^{\inf} \frac{f^n(c)}{n!}(x-c)^n =x - 0.5x^2 + 0.333x^3 -0.25x^4 + 0.2x^5 +...\)
f=expression(x^0.5)
taylor_expansion(f)
## expression(x^0.5)
## [1] "0x"
## [1] "Inf*x^1"
## [1] "-Inf*x^2"
## [1] "Inf*x^3"
## [1] "-Inf*x^4"
## [1] "Inf*x^5"
There is an unknown error with the above function for f(x) = x^(1/2).