Problems Key Idea 8.8.1 gives the \(n^{th}\) term of the Taylor series of common functions. In Exercises 3 – 6, verify the formula given in the Key Idea by finding the first few terms of the Taylor series of the given function and identifying a pattern.
library(calculus)
myf=function(x) exp(x)
taylor(myf, var=c(x=0), order=6)
## $f
## [1] "(1) * 1 + (0.999999999996052) * x^1 + (0.499999999979692) * x^2 + (0.166666665585433) * x^3 + (0.0416666593124569) * x^4 + (0.00833328285918537) * x^5 + (0.00138886379238021) * x^6"
##
## $order
## [1] 6
##
## $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.166666666 3
## 4 x^4 0.041666659 4
## 5 x^5 0.008333283 5
## 6 x^6 0.001388864 6
myf=function(x) sin(x)
taylor(myf, var=c(x=0), order=6)
## $f
## [1] "(1) * x^1 + (-0.166666665593812) * x^3 + (0.00833328307142597) * x^5"
##
## $order
## [1] 6
##
## $terms
## var coef degree
## 0 1 0.000000000 0
## 1 x^1 1.000000000 1
## 2 x^2 0.000000000 2
## 3 x^3 -0.166666666 3
## 4 x^4 0.000000000 4
## 5 x^5 0.008333283 5
## 6 x^6 0.000000000 6
myf=function(x) tan(x)
taylor(myf, var=c(x=0), order=6)
## $f
## [1] "(1) * x^1 + (0.333333040935881) * x^3 + (0.132895350565712) * x^5"
##
## $order
## [1] 6
##
## $terms
## var coef degree
## 0 1 0.0000000 0
## 1 x^1 1.0000000 1
## 2 x^2 0.0000000 2
## 3 x^3 0.3333330 3
## 4 x^4 0.0000000 4
## 5 x^5 0.1328954 5
## 6 x^6 0.0000000 6