Problem 10 Ex 8.8 page 496

Problem

find a formula for the nth term of the Taylor series of f(x), centered at c, by finding the coefficients of the first few powers of x and looking for a pattern

\[f(x)=ln(1+x)\]

Solution by hand:

The taylor series expansion is given by the following:

\[ f(x)=\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ n }(a) }{ n! } (x-a)^{n} } \\ =f(a)+f'(a)(x-a)+\frac{f''(a)}{2!}(x-a)^{2}+\frac{f'''(a)}{2!}(x-a)^{3}+... \]

Since c=0, we will be evaluating the Maclaurin series

We want to try and find the nth derivative by finding a few derivatives first and observing a pattern that may emerge

\[ f(x)=ln(1+x)\\ f'(x)=(x+1)^{-1}=\frac{1}{(x+1)}\\ f''(x)=-(x+1)^{-2}=-\frac{1}{(x+1)^{2}}\\ f'''(x)=2(x+1)^{-3}=\frac{2}{(x+1)^{3}}\\ f''''(x)=(2)(-3)(x+1)^{-4}=-\frac{(2)(3)}{(x+1)^{4}}\\ f'''''(x)=(2)(-3)(-4)(x+1)^{-5}=\frac{(2)(3)(4)}{(x+1)^{5}}\\ ...\\ ...\\ ...\\ f^{n}(x)=(-1)^{n}(n-1)!(x+1)^{-n}=(-1)^{n}\frac{(n-1)!}{(x+1)^{n}} \]

Value of derivatives when x=0:

\[ f(0)=ln(1+x)=ln(1+0)=0\\ f'(0)=\frac{1}{(0+1)}=1\\ f''(0)=-\frac{1}{(0+1)^{2}}=-1\\ f'''(0)=\frac{2}{(0+1)^{3}}=2\\ f''''(0)=-\frac{(2)(3)}{(0+1)^{4}}=-(2)(3)\\ f'''''(0)=\frac{(2)(3)(4)}{(x+1)^{5}}=(2)(3)(4)\\ ...\\ ...\\ ...\\ f^{n}(0)=(-1)^{n}\frac{(n-1)!}{(0+1)^{n}}=(-1)^{n}(n-1)! \]

Computing our nth Taylor Series

\[ T(x)=f(x)=\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ n }(a) }{ n! } (x-a)^{n} }\\ =\sum _{ n=0 }^{ \infty }{ \frac { (-1)^{n}(n-1)! }{ n! } (x)^{n} }\\ =\sum _{ n=0 }^{ \infty }{ \frac { (-1)^{n}(n-1)! }{ n(n-1)! } (x)^{n} }\\ =\sum _{ n=0 }^{ \infty } (-1)^{n} \frac{x^{n}}{n} \]

Chacking approximation using pracma

library(pracma)
f <- function(x) log(1+x)
p <- taylor(f, 0, 4)

x <- seq(-1.0, 1.0, length.out=100)
yf <- f(x)
yp <- polyval(p, x)
plot(x, yf, type = "l", main =' Taylor Series Approximation of 1/(1-x)',col = "blue", lwd = 3)
lines(x, yp, col = "red")
legend('topleft', inset=.05, legend= c("Approximation using Taylor Series", "f(x)=1/(1+x)")
       , lwd=c(2.5,2.5), col=c('red', 'blue'), bty='n', cex=.75)

Source: https://www.rdocumentation.org/packages/pracma/versions/1.9.9/topics/taylor

Expansion using rSympy

library(rSymPy)
sympy("var('x')")
## [1] "x"
sympy("var('p')")
## [1] "p"
sympy("var('1+x')") 
## [1] "1+x"
xt <- sympy("p=series(log(1+x), x, 0, 15)")#returns the first 15 orders of the series
print(xt)         
## [1] "x - x**2/2 + x**3/3 - x**4/4 + x**5/5 - x**6/6 + x**7/7 - x**8/8 + x**9/9 - x**10/10 + x**11/11 - x**12/12 + x**13/13 - x**14/14 + O(x**15)"