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:
<- function(x) { 1/(1-x)}
f1<- taylor(f1,0,5)
taylor_f1
<- seq(-1.0, 1.0, length.out = 50)
x1<- f1(x1)
y1
<- polyval(taylor_f1, x1)
yr_taylor 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:
<- function(x) {
f2<-exp(1)
ereturn(e^x) }
<- taylor(f2,0,5)
taylor_f2
<- seq(-1.0, 1.0, length.out = 900)
x2<- f2(x2)
y2
<- polyval(taylor_f2, x2)
yr_taylor 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
<- function(x) {log(1+x)}
f taylor(f, 0, 4)
## [1] -0.2500044 0.3333339 -0.5000000 1.0000000 0.0000000
Question 4:
\[f(x) = {x}^{1/2}\]
R code
<- function(x) {x^(1/2)}
f taylor(f, 1, 4)
## [1] -0.03906285 0.21875150 -0.54687738 1.09375167 0.27343706