library(calculus)
## Warning: package 'calculus' was built under R version 4.3.3
taylor_f1 <- taylor(f = expression(1 - x), var = "x", order = 5)
print(taylor_f1)
## $f
## [1] "(1) * 1 + (-1) * x^1"
##
## $order
## [1] 5
##
## $terms
## var coef degree
## 0 1 1 0
## 1 x^1 -1 1
## 2 x^2 0 2
## 3 x^3 0 3
## 4 x^4 0 4
## 5 x^5 0 5
taylor_f2 <- taylor(f = expression(exp(x)), var = "x", order = 5)
print(taylor_f2)
## $f
## [1] "(1) * 1 + (1) * x^1 + (0.5) * x^2 + (0.166666666666667) * x^3 + (0.0416666666666667) * x^4 + (0.00833333333333333) * x^5"
##
## $order
## [1] 5
##
## $terms
## var coef degree
## 0 1 1.000000000 0
## 1 x^1 1.000000000 1
## 2 x^2 0.500000000 2
## 3 x^3 0.166666667 3
## 4 x^4 0.041666667 4
## 5 x^5 0.008333333 5
#f(x) = ln(1 + x)
taylor_f3 <- taylor(f = expression(log(1 + x)), var = "x", order = 5)
print(taylor_f3)
## $f
## [1] "(1) * x^1 + (-0.5) * x^2 + (0.333333333333333) * x^3 + (-0.25) * x^4 + (0.2) * x^5"
##
## $order
## [1] 5
##
## $terms
## var coef degree
## 0 1 0.0000000 0
## 1 x^1 1.0000000 1
## 2 x^2 -0.5000000 2
## 3 x^3 0.3333333 3
## 4 x^4 -0.2500000 4
## 5 x^5 0.2000000 5
#f(x) = x^(1/2)
taylor_f4 <- taylor(f = expression(x^(1/2)), var = "x", order = 5)
print(taylor_f4)
## $f
## [1] "(Inf) * x^1 + (-Inf) * x^2 + (Inf) * x^3 + (-Inf) * x^4 + (Inf) * x^5"
##
## $order
## [1] 5
##
## $terms
## var coef degree
## 0 1 0 0
## 1 x^1 Inf 1
## 2 x^2 -Inf 2
## 3 x^3 Inf 3
## 4 x^4 -Inf 4
## 5 x^5 Inf 5