\[f(x) = \frac{1}{1-x}\] \[= \sum_{n=0}^{\infty} x^{n}\] \[= 1 + x + x^2 + x^3 + x^4 + ...\]
taylorSeries1 <- function (xvalue, n){
result <- sum(sapply(c(0:n), function(x) xvalue^x ))
return(result)
}
taylorSeries1(1/2,5)
## [1] 1.96875
taylorSeries1(1/2,20)
## [1] 1.999999
taylorSeries1(1/2,40)
## [1] 2
taylorSeries1(1/2,60)
## [1] 2
\[f(x) = e^x\] \[= \sum_{n=0}^{\infty} \frac{x^n}{n!}\] \[= 1 + x + \frac{x^2}{2} + \frac{x^3}{3} + ...\]
taylorSeries2 <- function (xvalue, n){
result <- sum(sapply(c(0:n), function(x) (xvalue^x)/factorial(x) ))
return(result)
}
taylorSeries2(1/2,5)
## [1] 1.648698
taylorSeries2(1/2,20)
## [1] 1.648721
taylorSeries2(1/2,40)
## [1] 1.648721
taylorSeries2(1/2,60)
## [1] 1.648721
\[f(x) = ln(1+x)\]
We know,
\[f^1(x) = \frac{1}{1+x} -> f^1(0) = 1\] \[f^2(x) = -\frac{1}{(1+x)^2} -> f^2(0) = -1\] \[f^3(x) = -\frac{1}{(1+x)^3} -> f^3(0) = 2\] \[f^4(x) = -\frac{1}{(1+x)^4} -> f^4(0) = -6\]
\[= \sum_{n=0}^{\infty} (-1)^{n+1}\frac{x^n}{n}\] \[= \sum_{n=0}^{\infty} (-1)^{n+1}\frac{x^n}{n}\]
We get, \[f^n(0) = (-1)^n * (n-1)!\]
Therefore, \[f(x) = ln(1+x) = \sum_{n=1}^{\infty} (-1)^n(n-1)! \frac{x^n}{n!}\] \[=\sum_{n=1}^{\infty} (-1)^n\frac{x^n}{n}\] \[=\sum_{n=0}^{\infty} (-1)^n\frac{x^n+1}{n+1}\] \[=x - \frac{x^2}{2} + \frac{x^3}{3} + \frac{x^4}{4} + ... \]
taylorSeries3 <- function (xvalue, n){
result <- sum(sapply(c(0:n),
function(x)
(-1)^(x) * (xvalue^(x+1)/(x+1))))
return(result)
}
taylorSeries3(1/2,5)
## [1] 0.4046875
taylorSeries3(1/2,20)
## [1] 0.4054651
taylorSeries3(1/2,40)
## [1] 0.4054651
taylorSeries3(1/2,60)
## [1] 0.4054651
The larger the n, the precise the value of the function at given point.