\(~\)
\(~\)
\(f(x)=\frac{1}{(1 - x)}\)
\(f(a)=\frac{1}{1 - a}\) : \(f(0) = 1\)
\(f'(a)=\frac{1}{(1 - a)^2}\) : \(f^{(1)}(0) = 1\)
\(f''(a)=\frac{2}{(1 - a)^3}\) : \(f^{(2)}(0) = 2\)
\(f'''(a)=\frac{6}{(1 - a)^4}\) : \(f^{(3)}(0) = 6\)
\(f^{(4)}(a)=\frac{24}{(1 - a)^5}\) : \(f^{(4)}(0) = 24\)
\(= f(a)+f'(a)(x-a)+\frac{f''(a)}{2!}(x-a)^2+\frac{f'''(a)}{3!}(x-a)^3+...\)
generalized as: \(f^{(n)}(x) = \frac{n!}{(1-x)^{n+1}}\)
substituting the general equation: \(\frac{1}{1-x} \approx \sum_{n=0}^{\infty}\frac{n!}{(1-a)^{n+1}}\times \frac{(x-a)^n}{n!} = \frac{(x-a)^n}{(1-a)^n}\)
when a = 0 it becomes: \(\frac{1}{1-x} \approx \sum_{n=0}^{\infty}x^n\)
\(~\)
\(f(x) = e^x\)
The derivative of \(f(x) = e^x\) is \(e^x\) and any derivative of \(f^{(n)}(x)=e^x\)
At a = 0 it becomes: \(\frac{1}{1-x} \approx \sum_{n=0}^{\infty}\frac{x^n}{n!}\)
\(~\)
\(f(x) = ln(1+x)\)
\(f(x) = ln(x)\)
\(f^{(1)}(x) = \frac{1}{1+x}\)
\(f^{(2)}(x) = \frac{-1}{(1+x)^2}\)
\(f^{(3)}(x) = \frac{2}{(1+x)^3}\)
\(f^{(4)}(x) = \frac{-6}{(1+x)^4}\)
generalized as: \(f^{(n)}(x) = (-1)^{n-1}\frac{(n-1)!}{(1+x)^n}\)
substitute to the general equation: \(ln(1 + x) \approx \sum_{n = 0}^{\infty} (-1)^{n - 1} \frac{(n - 1)!}{(1 + a)^n}\times\frac{(x - a)^a}{n!} = (-1)^{n - 1}\frac{(x - a)^n}{n(1 + a)^n}\)
when a = 0 it becomes: \(ln(1+x) \approx \sum_{n=0}^{\infty}(-1)^{n-1}\frac{x^n} {n}\)
\(~\)
\(f(x) = x^{(\frac{1}{2})}\)
defined as: \(f(x) = f(a) + \frac{f'(a)}{1!}(x - a) + \frac{f''(a)}{2!}(x - a)^2 + \frac{f''"(a)}{3!}(x - a)^3 + ...\)
derivatives: \(= 1 + \frac{\frac{1}{2}}{1!}(x - 1) + \frac{-\frac{1}{4}}{2!}(x - 1)^2 + \frac{\frac{3}{8}}{3!}(x - 1)^3 + \frac{-\frac{15}{16}}{4!}(x - 1)^4\)
refine: \(= 1 + \frac{1}{2}(x - 1) - \frac{1}{8}(x - 1)^2 + \frac{1}{16}(x - 1)^3 - \frac{5}{128}(x - 1)^4 + ...\)
\(~\)
library(pracma)
library(expm)
# Equation 1
<- function(x) (1/(1-x))
f <- taylor(f, 0, 5)
p p
## [1] 1.000293 1.000029 1.000003 1.000000 1.000000 1.000000
sum(p)
## [1] 6.000325
<- seq(-1, 8, length.out = 100)
x <- f(x)
yf <- polyval(p, x)
yp plot(x, yf, type = "l", main = "Taylor Series Approximation Equation 1", col = "blue", lwd = 3)
lines(x, yp, col = "red")
grid()
# Equation 2
<- function(x) exp(x)
f_2 <- taylor(f_2, 0, 5)
p_2 p_2
## [1] 0.008334245 0.041666573 0.166666726 0.499999996 1.000000000 1.000000000
sum(p_2)
## [1] 2.716668
<- seq(-1, 8, length.out = 100)
x_2 <- f(x_2)
yf_2 <- polyval(p_2, x_2)
yp_2 plot(x_2, yf_2, type = "l", main = "Taylor Series Approximation Equation 2", col = "blue", lwd = 3)
lines(x_2, yp_2, col = "red")
grid()
# Equation 3
<- function(x) (log(1 + x))
f_3 <- taylor(f_3, 0, 5)
p_3 p_3
## [1] 0.2000413 -0.2500044 0.3333339 -0.5000000 1.0000000 0.0000000
sum(p_3)
## [1] 0.7833707
<- seq(-1, 8, length.out = 100)
x_3 <- f(x_3)
yf_3 <- polyval(p_3, x_3)
yp_3 plot(x_3, yf_3, type = "l", main = "Taylor Series Approximation Equation 3", col = "blue", lwd = 3)
lines(x_3, yp_3, col = "red")
grid()
# Equation 4
<- function(x) {ifelse(x == 0, (1/2), f(x))}
f_4 <- taylor(f_4, x0 = 0, n = 5)
p_4 p_4
## [1] 1.000293e+00 -3.408918e+09 1.000003e+00 3.355443e+07 1.000000e+00
## [6] 5.000000e-01
sum(p_4)
## [1] -3375363364
<- seq(-1, 8, length.out = 100)
x_4 <- f(x_4)
yf_4 <- polyval(p_4, x_4)
yp_4 plot(x_4, yf_4, type = "l", main = "Taylor Series Approximation Equation 4", col = "blue", lwd = 3)
lines(x_4, yp_4, col = "red")
grid()
Do equation 4 make sense? Is there something I am missing or not doing correctly?