This week, we’ll work out some Taylor Series expansions of popular functions.
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 a R-Markdown document.
The Taylor Series of f(x), centered at c is
\(f(c)=\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(c) }{ n! } { (x-c) }^{ n } }\)
Setting c = 0 gives the Maclaurin Series of f(x):
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } }\)
\(f(x)=\frac { 1 }{ (1-x) }\)
If centered at c=0,
\(f'(0)=\frac { 1 }{ { (1-x) }^{ 2 } }=1\)
\(f''(0)=\frac { 2 }{ { (1-x) }^{ 3 } } =2\)
\(f'''(0)=\frac { 6 }{ { (1-x) }^{ 4 } } =6\)
\(f''''(0)=\frac { 24 }{ { (1-x) }^{ 5 } } =24\)
So,
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } =\frac { 1 }{ (1-0) } +\frac { \frac { 1 }{ { (1-0) }^{ 2 } } }{ 1! } { x }^{ 1 }+\frac { \frac { 2 }{ { (1-0) }^{ 3 } } }{ 2! } { x }^{ 2 }+\frac { \frac { 6 }{ { (1-0) }^{ 4 } } }{ 3! } { x }^{ 3 }+\frac { \frac { 24 }{ { (1-0) }^{ 5 } } }{ 4! } { x }^{ 4 }+...\)
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } =1+{ x }^{ 1 }+{ x }^{ 2 }+{ x }^{ 3 }+{ x }^{ 4 }+...\)
\(\sum _{ n=0 }^{ \infty }{ { x }^{ n } }\)
Example of using the taylor() function from the pracma package in R to calculate the first 4 coefficients of the Taylor series through numerical differentiation:
library(pracma)
f <- function(x) 1/(1-x)
p <- taylor(f, 0, 4)
p
## [1] 1.000029 1.000003 1.000000 1.000000 1.000000
\(f(x)={ e }^{ x }\)
If centered at c=0,
\(f'(0)={ e }^{ x }=1\)
\(f''(0)={ e }^{ x }=1\)
\(f'''(0)={ e }^{ x }=1\)
\(f''''(0)={ e }^{ x }=1\)
So,
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } ={ e }^{ 0 }+\frac { { e }^{ 1 } }{ 1! } { x }^{ 1 }+\frac { { e }^{ 2 } }{ 2! } { x }^{ 2 }+\frac { { e }^{ 3 } }{ 3! } { x }^{ 3 }+\frac { { e }^{ 4 } }{ 4! } { x }^{ 4 }+...\)
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } =1+\frac { 1 }{ 1! } { x }^{ 1 }+\frac { 1 }{ 2! } { x }^{ 2 }+\frac { 1 }{ 3! } { x }^{ 3 }+\frac { 1 }{ 4! } { x }^{ 4 }+...\)
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } }\)
Example of using the taylor() function from the pracma package in R to calculate the first 4 coefficients of the Taylor series through numerical differentiation:
library(pracma)
f <- function(x) exp(x)
p <- taylor(f, 0, 4)
p
## [1] 0.04166657 0.16666673 0.50000000 1.00000000 1.00000000
\(f(x)=ln(1+x)\)
If centered at c=0,
\(\frac { d }{ dx } \left[ ln(x+1 \right] =\frac { 1 }{ x+1 } \frac { d }{ dx } [x+1]\)
\(\frac { d }{ dx } \left[ ln(x+1 \right] =\frac { \frac { d }{ dx } [x]+\frac { d }{ dx } [1] }{ x+1 }\)
\(\frac { d }{ dx } \left[ ln(x+1 \right] =\frac { 1+0 }{ x+1 }\)
\(\frac { d }{ dx } \left[ ln(x+1 \right] =\frac { 1 }{ x+1 }\)
\(f'(0)=\frac { 1 }{ x+1 } =1\)
\(f''(0)=-\frac { 1 }{ { (1+x) }^{ 2 } } =-1\)
\(f'''(0)=\frac { 2 }{ { (1+x) }^{ 3 } } =2\)
\(f''''(0)=-\frac { 6 }{ { (1+x) }^{ 4 } } =-6\)
So,
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } =ln(1+0)+\frac { \frac { 1 }{ 0+1 } }{ 1! } { x }^{ 1 }+\frac { -\frac { 1 }{ { (1+0) }^{ 2 } } }{ 2! } { x }^{ 2 }+\frac { \frac { 2 }{ { (1+0) }^{ 3 } } }{ 3! } { x }^{ 3 }+\frac { -\frac { 6 }{ { (1+0) }^{ 4 } } }{ 4! } { x }^{ 4 }+...\)
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } =0+\frac { 1 }{ 1! } { x }^{ 1 }+\frac { -1 }{ 2! } { x }^{ 2 }+\frac { 2 }{ 3! } { x }^{ 3 }+\frac { -6 }{ 4! } { x }^{ 4 }+...\)
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } =x-\frac { 1 }{ 2 } { x }^{ 2 }+\frac { 1 }{ 3 } { x }^{ 3 }-\frac { 1 }{ 4 } { x }^{ 4 }+...\)
\(\sum _{ n=0 }^{ \infty }{ \frac { { f }^{ (n) }(0) }{ n! } { x }^{ n } } =\sum _{ n=0 }^{ \infty }{ { (-1) }^{ n+1 }\frac { 1 }{ n } } { x }^{ n }\)
Example of using the taylor() function from the pracma package in R to calculate the first 4 coefficients of the Taylor series through numerical differentiation:
library(pracma)
f <- function(x) log(1+x)
p <- taylor(f, 0, 4)
p
## [1] -0.2500044 0.3333339 -0.5000000 1.0000000 0.0000000