This week, we’ll work out some Taylor Series expansions of popular functions
\(f(x) = \frac {1}{(1-x)}\)
library(calculus)
myf=function(x) 1/(1-x)
taylor(myf, var=c(x=1), order=6)
## $f
## [1] "(NaN) * 1 + (NaN) * (x-1)^1 + (-Inf) * (x-1)^2 + (Inf) * (x-1)^3 + (Inf) * (x-1)^4 + (Inf) * (x-1)^5 + (-Inf) * (x-1)^6"
##
## $order
## [1] 6
##
## $terms
## var coef degree
## 0 1 NaN 0
## 1 (x-1)^1 NaN 1
## 2 (x-1)^2 -Inf 2
## 3 (x-1)^3 Inf 3
## 4 (x-1)^4 Inf 4
## 5 (x-1)^5 Inf 5
## 6 (x-1)^6 -Inf 6
for this expression:
\(f(x) = e^x\)
myf=function(x) exp(x)
taylor(myf, var=c(x=1), order=6)
## $f
## [1] "(2.71828182845905) * 1 + (2.71828182841867) * (x-1)^1 + (1.35914091422767) * (x-1)^2 + (0.453046968460462) * (x-1)^3 + (0.113261722854398) * (x-1)^4 + (0.0226522113653448) * (x-1)^5 + (0.00377532322101908) * (x-1)^6"
##
## $order
## [1] 6
##
## $terms
## var coef degree
## 0 1 2.718281828 0
## 1 (x-1)^1 2.718281828 1
## 2 (x-1)^2 1.359140914 2
## 3 (x-1)^3 0.453046968 3
## 4 (x-1)^4 0.113261723 4
## 5 (x-1)^5 0.022652211 5
## 6 (x-1)^6 0.003775323 6
for the expression : \(f(x) = ln(1+x)\)
myf=function(x) log1p(x)
taylor(myf, var=c(x=1), order=6)
## $f
## [1] "(0.693147180559945) * 1 + (0.499999999986567) * (x-1)^1 + (-0.124999999994923) * (x-1)^2 + (0.0416666606239297) * (x-1)^3 + (-0.0156248541677676) * (x-1)^4 + (0.00624584827100866) * (x-1)^5 + (-0.00259432533680781) * (x-1)^6"
##
## $order
## [1] 6
##
## $terms
## var coef degree
## 0 1 0.693147181 0
## 1 (x-1)^1 0.500000000 1
## 2 (x-1)^2 -0.125000000 2
## 3 (x-1)^3 0.041666661 3
## 4 (x-1)^4 -0.015624854 4
## 5 (x-1)^5 0.006245848 5
## 6 (x-1)^6 -0.002594325 6
for the expression: \(f(x) = x^{(1/2)}\)
myf=function(x) x^(1/2)
taylor(myf, var=c(x=1), order=6)
## $f
## [1] "(1) * 1 + (0.499999999993442) * (x-1)^1 + (-0.125000000007528) * (x-1)^2 + (0.0624999125751056) * (x-1)^3 + (-0.0390585237804083) * (x-1)^4 + (0.0271073977955759) * (x-1)^5 + (-0.0192319502234077) * (x-1)^6"
##
## $order
## [1] 6
##
## $terms
## var coef degree
## 0 1 1.00000000 0
## 1 (x-1)^1 0.50000000 1
## 2 (x-1)^2 -0.12500000 2
## 3 (x-1)^3 0.06249991 3
## 4 (x-1)^4 -0.03905852 4
## 5 (x-1)^5 0.02710740 5
## 6 (x-1)^6 -0.01923195 6