library(pracma)

ASSIGNMENT 14 - TAYLOR SERIES

IS 605 FUNDAMENTALS OF COMPUTATIONAL MATHEMATICS - 2021

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

• f (x) = 1/(1−x) • f (x) = ex • f (x) = ln(1 + x) • f(x)=x(1/2)

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 an R- Markdown document.

Question 1:

\[{f(x)} = \frac{1}{(1-x)}\]

The Taylor Series of f(x), centered at c is:

\[f(x) = \sum_{n=0}^\infty \frac{(f)^n (c)}{(n)!}{(x-c)^n}\]

Let’s calculate the derivative first

\[{f'(x)} = \frac{1}{(1-x)^2}\]

\[{f''(x)} = \frac{2}{(1-x)^3}\]

\[{f'''(x)} = \frac{6}{(1-x)^4}\]

Find the nth term

\[f(x) = \sum_{n=0}^\infty\frac{(f)^n (c)}{(n)!}{(x-c)^n}\]

\[\frac{1}{(1-c)^2 1!}{(x-c)}^1 +\frac{2}{(1-c)^3 2!}{(x-c)}^2+\frac{6}{(1-c)^4 3!}{(x-c)}^3+ \frac{24}{(1-c)^5 4!}{(x-c)}^4+..........\]

\[f(x) = \sum_{n=0}^\infty\frac{1}{(1-c)^n+1}{(x-c)^n}\]

When c= 0

\[f(x)= {\sum_{n=0}^\infty\{x^n}\]

\[1+x+x^2+x^3+x4+....\]

R Code:

f1<- function(x) { 1/(1-x)}
taylor_f1 <- taylor(f1,0,5)

x1<- seq(-1.0, 1.0, length.out = 50)
y1 <- f1(x1)

yr_taylor <- polyval(taylor_f1, x1)
plot(x1, y1, type = "l", main= '1/(1-x) Taylor Series' ,col = "Green", lwd = .1)

Question 2:

\[ {f (x)} = {e^x}\]

\[f'(x) = e^x\] \[f''(x) = e^x\]

\[f'''(x) = e^x\]

Let’s find the nth term for the Taylors series

\[f(x) = \sum_{n=0}^\infty\frac{(f)^n (c)}{(n)!}{(x-c)^n}\]

\[\frac{e^c}{(1)!}{(x-c)^1} +\frac{e^c}{(2)!}{(x-c)^2} +\frac{e^c}{(3)!}{(x-c)^3}+............\]

\[\sum_{n=0}^\infty\frac{e^c}{(n)!}{(x-c)^n}\] When c= 0

\[\sum_{n=0}^\infty\frac{1}{(n)!}{(x)^n}\] \[1+ x+\frac{1}{2}{x^2}+\frac{1}{6}{x^3}+.......\]

R Code:

f2<- function(x) { 
  e<-exp(1) 
  return(e^x) }
taylor_f2 <- taylor(f2,0,5)

x2<- seq(-1.0, 1.0, length.out = 900)
y2 <- f2(x2)

yr_taylor <- polyval(taylor_f2, x2)
plot(x2, y2, type = "l", main= 'e^x Taylor Series' ,col = "Green", lwd = .1)

Question 3:

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

\[{f'(c)} = \frac{1}{(1+c)}\]

\[{f''(c)} =- \frac{1}{(1+c)^2}\]

\[{f'''(c)} = \frac{1}{(1+c)^3}\]

\[{f''''(c)} = -\frac{1}{(1+c)^4}\]

We look for the pattern of the nth term in the taylor series centered at c=0

\[f(x) = \sum_{n=0}^\infty \frac{(f)^n (c)}{(n)!}{(x-c)^n}\]

\[ \frac{1}{(1+c) (n)!}{(x-c)^1}-\frac{1}{(1+c)^2 (n)!}{(x-c)^2}+\frac{2}{(1+c)^3 (n)!}{(x-c)^3}-\frac{6}{(1+c)^4 (n)!}{(x-c)^4}\]

\[ \sum_{n=0}^\infty \frac{(-1)^n+1}{(1+c)(n)!}{(x-c)^n}\]

\[0+x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+....\]

\[ \sum_{n=0}^\infty \frac{(-1)^n+1}{n}{x^n}\]

R code

 f <- function(x) {log(1+x)}
taylor(f, 0, 4)
## [1] -0.2500044  0.3333339 -0.5000000  1.0000000  0.0000000

Question 4:

\[f(x) = {x}^{1/2}\]

R code

f <- function(x) {x^(1/2)}
taylor(f, 1, 4)
## [1] -0.03906285  0.21875150 -0.54687738  1.09375167  0.27343706

References:

https://www.youtube.com/watch?v=SX2lZ7ZVHu0

https://math.stackexchange.com/questions/996449/is-the-square-root-of-the-absolute-value-function-sqrtx-differentiable

https://latexeditor.lagrida.com/

https://bookdown.org/yihui/rmarkdown-cookbook/