Taylor Series

The formula for Taylor Series is below

\[f(x)= \sum_{n=0}^{\infty} \dfrac{f^{n} (a)}{n!}(x-a)^n \\\] \[ = f(a)+f`(a)(x-a)+\dfrac{f``(a)}{2!}(x-a)^2+\dfrac{f```(a)}{3!}(x-a)^3+\dfrac{f````(a)}{4!}(x-a)^4 \\\]

We can appy the formula for all the function mentioned

f(x) = 1/(1-x)

First step is to calculate the coefficients at a=0

\[f(x) = \dfrac{1}{(1-x)} = (1-x)^{-1}\] \[ f(0) = (1-x)^{-1}\] \[ f`(0) = (1-x)^{-2}=1\] \[ f``(0) = 2(1-x)^{-3}=2\] \[ f```(0) = 6(1-x)^{-4}=6\] \[ f````(0) = 24(1-x)^{-4}=24\] \[ f^{n}(x) = n!(1-x)^{-n}\]

Substituting the above in taylor series equation we get

\[Tn(x)=1+x+\dfrac{2}{2!} x^2+\dfrac{6}{3!} x^3+\dfrac{24}{4!} x^4+...\]

\[f(x)=1+x+x^2+x^3+x^4\] Verify the coeffiecients using R function

library(pracma)
## Warning: package 'pracma' was built under R version 3.6.3
f <- function(x) 1/(1-x)

p <- round(taylor(f, 0, 4),2)
p
## [1] 1 1 1 1 1

The values are matching with the coefficients in taylor series equation

Plot the Taylor Series Function

library(pracma)

f <- function(x) 1/(1-x)

p <- round(taylor(f, 0, 4),2)
p
## [1] 1 1 1 1 1
s<- seq(-1.0, 1.0,0.1)
f_s <- f(s)

plt_taylor <- polyval(p, s)
plot(s, plt_taylor,type="l",col="red")

f(x) = exp(x)

First step is to calculate the coefficients at a=0

\[f(x) = e^x \] \[ f`(0) = e^1=1\] \[ f``(0) = e^2=1\] \[ f```(0) = e^2=1\] \[ f````(0) = e^2=1\] \[ f^{n}(x) = e^{n}\]

Substituting the above in taylor series equation we get

\[Tn(x)=1+x+\dfrac{x^2}{2!} +\dfrac{x^3}{3!} +\dfrac{x^4}{4!} +...\]

Verify the coeffiecients using R function

library(pracma)

f <- function(x) exp(x)

p <- round(taylor(f, 0, 4),2)
p
## [1] 0.04 0.17 0.50 1.00 1.00

Plot the Taylor Series Function

library(pracma)

f <- function(x) exp(x)

p <- round(taylor(f, 0, 4),2)
p
## [1] 0.04 0.17 0.50 1.00 1.00
s<- seq(-1.0, 1.0,0.1)
f_s <- f(s)

plt_taylor <- polyval(p, s)
plot(s, plt_taylor,type="l",col="red")

f(x) = ln(1+x)

First step is to calculate the coefficients at a=0

\[f(x) = ln(1+x), f`(x)=\dfrac{1}{(1+x)}=(1+x)^{-1} \] \[ f(0) = ln(1)=0\] \[ f`(0) = (1+0)^-1=1\] \[ f``(0) = -1(1+0)^-2=-1\] \[ f```(0) = 2(1+0)^-3=2\] \[ f````(0) = -6(1+0)^-4=-6\] \[ f^{n}(x) = (-1)^{n+1}(n-1)!\]

Substituting the above in taylor series equation we get

\[Tn(x)=0+x-\dfrac{x^2}{2!} +2\dfrac{x^3}{3!} -6\dfrac{x^4}{4!} +...\] \[Tn(x)=0+x-\dfrac{1}{2}x^2 +\dfrac{1}{3}x^3-\dfrac{1}{4}x^4\]

library(pracma)

f <- function(x) log(1+x)

p <- round(taylor(f, 0, 4),2)
p
## [1] -0.25  0.33 -0.50  1.00  0.00

Plot the Taylor Series Function

library(pracma)

f <- function(x) log(1+x)

p <- round(taylor(f, 0, 4),2)
p
## [1] -0.25  0.33 -0.50  1.00  0.00
s<- seq(-1.0, 1.0,0.1)
f_s <- f(s)

plt_taylor <- polyval(p, s)
plot(s, plt_taylor,type="l",col="red")

The values matches with the coeffieicients obtained in taylor series