In its most general terms, the value of a function, f (x), in the vicinity of the point x0 = a, is given by:
\[f(x) = f(a) + \frac {f^1(a)(x - a)} {1!} + \frac {f^2(a)(x - a)} {2!} + \frac {f^3(a)(x - a)} {3!} + ... \]
which can be expressed in summation form:
\[f(x) = \sum_{n=0}^{\infty} \frac{f^{n} (a)}{n!} (x -a)^n \qquad Eq.1\]
\[ f(x) = \frac{1} {(1 -x)} \]
When evaluated at x = 0, f (0) = 1. Let’ s look at successive derivatives of the function
\[ \begin{align} & f^{(1)}(x) = (-1)(-1) \frac{1}{(1-x)^2} = \frac{1} {1} \quad \Rightarrow f^{(1)}(0)= 1\\ & f^{(2)}(x) = (-1)^2 (-1)(-2) \frac{1}{(1-x)^3} = \frac{2} {1} \quad \Rightarrow f^{(2)}(0)= 2\\\\ & f^{(3)}(x) = (-1)^3 (-1)(-2)(-3) \frac{1}{(1-x)^4} = \frac{6} {1} \quad \Rightarrow f^{(3)}(0)= 6\\\\ \end{align} \]
In general form, the nth derivative is:
\[ \begin{align} f(x) = \frac{1} {1-x} = &\sum_{n=0}^{\infty} \frac{(n!)(x)^n} {(n!)} \\ = &\sum_{n=0}^{\infty} (x)^n\\ = &1 + x + x^2 + x^3 + x^4 + x^5 + ... \end{align} \]
The above expression converges only as long as | x | < 1, since it is clear that the denominator goes to zero as x approaches 1..
So, let’s see how well this series converges to function, f (x) = 1/(1 - x). If x = 1/2, the f(1/2) = 2. let’s see what we obtain if we calculate the sum of the first 10 and 20 terms of the Taylor expansion:
ExpansionTest<- function(x,n) {
y=0
for (i in 0:n) y = y + sum(x^i)
return(y)
}
ExpansionTest(1/2, 10)
## [1] 1.999023
ExpansionTest(1/2, 20)
## [1] 1.999999
ExpansionTest(1/2, 30)
## [1] 2
As expected when x = 1/2, f(x) = 1/(1 - x) = 2; Also the expansion converges toward 2 as the power series increases.
Below is a plot the f(x) and polynomial approximation through Taylor series p(x):
library(pracma)
f <- function(x) (1/(1-x))
p <- taylor(f, 0, 5)
x <- seq(-1.0, 1.0, length.out=100)
yf <- f(x)
yp <- polyval(p, x)
plot(x, yf, type = "l", main =' Taylor Series Approximation of 1/(1-x)',col = "blue", lwd = 3)
lines(x, yp, col = "red")
legend('topleft', inset=.05, legend= c("Taylor Series", "f(x)=1/(1+x)")
, lwd=c(2.5,2.5), col=c('red', 'blue'), bty='n', cex=.75)
\[ f(x) = e^x \]
Using Eq.1 above and replace f(x) with e^x and f’(x) with e^x, we get:
\[ e^x = \sum_{0}^{\infty} \frac{e^a}{n!} {(x-a)^n} \qquad Eq.2\]
Recall, the power series centered at c with coefficients a_n is:
\[ \sum_{0}^{\infty} a_n{(x-c)^n} \]
First note that Eq.2 is a power series centered at c = 0, and the coefficients a_n =1/n!. We will use the ratio test to find the radius of convergence as follow:
\[ \begin{align} \lim_{x\to\infty } \frac {a_{n+1} x^{n+1}} {a_n x^n} = &\lim_{x\to\infty } \frac {\frac{x^{n+1}} {(n+1)!}} {\frac {x^n} {n!}} \\ = &\lim_{n\to\infty } \frac {x^{n+1}{n!}} {{(n+1)!} {x^n}} \\ = & \lim_{n\to\infty } \frac {{x^n}{n!}{x}} {{(n+1)}{n!}{x^n}} \\ = & \lim_{n\to\infty } \frac {x} {(n+1)} \end{align} \]
The result of ratio test above implies that this series converges and it does not depend on x.
Below is a plot the f(x) and polynomial approximation through Taylor series p(x)
library(pracma)
f <- function(x) {
e <- exp(1)
return(e^x)
}
p <- taylor(f, 0, 5)
x <- seq(-1.0, 1.0, length.out=100)
yf <- f(x)
yp <- polyval(p, x)
plot(x, yf, type = "l", main =' Taylor Series Approximation of e^x', col = "blue", lwd = 3)
lines(x, yp, col = "red")
legend('topleft', inset=.05, legend= c("Taylor Series", "f(x)=e^x")
, lwd=c(2.5,2.5), col=c('red', 'blue'), bty='n', cex=.75)
\[ f(x) = ln( 1 + x ) \]
First lets find the derivative of ln(1+x). Applying the differentiation rule, we get:
\[ \begin{align} [ln( 1 + x ) ]' = &\frac {1} {1+x} (1 + x)' \\ = &\frac {1} {1+x} (0 + 1) \\ = &\frac {1} {1+x} \\ \end{align} \]
Now let’s find the subsequent deirivatives:
\[ \begin{align} [ln( 1 + x ) ]^2 = &[(1+x)^{-1}]' \\ = &(-1){(1+x)}^{-2} \end{align} \]
\[ \begin{align} [ln( 1 + x ) ]^3 = &[(-1){(1+x)}^{-2}]' \\ = &{(-1}{(-2)}{(1+x)}^{-3} \end{align} \]
\[ \begin{align} [ln( 1 + x ) ]^4 = &[(-1){(1+x)}^{-3}]' \\ = &{(-1}{(-2)}{(-3)}{(1+x)}^{-4} \end{align} \]
from above derivatives, we see that:
\[ \begin{align} [ln( 1 + x ) ]^n = &(-1)^{n-1} (n-1)! {(1+x)}^{-n} \\ = &(-1)^{n-1} (n-1)! \frac {1} {(1+x)^{n}} \end{align} \]
Hence, from Eq.1, for a = 0:
\[ ln( 1 + x ) = \sum_{n>=1}^{\infty} \frac {(-1)^{n-1} (n-1)!} {n!} x^n \]
Also, n! can be written as:
\[ n! = n (n -1)!\]
Therefore, ln( 1 + x ) is:
\[ \begin{align} ln( 1 + x ) =& \sum_{n>=1}^{\infty} \frac {(-1)^{n-1} (n-1)!} {n(n-1)!} x^n \\ =& \sum_{n>=1}^{\infty} (-1)^{n-1} \frac {x^n} {n} \end{align} \]
\[ \begin{align} ln( 1 + x ) = \sum_{n>=0}^{\infty} \frac {(-1)^{n}} {n+1} {x^{n+1}} \end{align} \]
\[ ln( 1 + x ) = \frac {x} {1} - \frac {x^2} {2} +\frac {x^3} {3} - \frac {x^4} {4} + \frac {x^5} {5} + .... \]
We will use the ratio test to find the radius of convergence as follow:
\[ \begin{align} \lim_{n\to\infty } \frac {a_{n+1} x^{n+1}} {a_n x^n} = & \lim_{n\to\infty } \frac {\frac {{-1}^n x^{n+1}} {n+1}} {\frac {{-1}^{n-1} x^{n}} {n}} \\ =&\lim_{n\to\infty } \frac {-1^n (x)^{n+1} n} {(n+1) (-1)^{n-1} x^n} \\ =&\lim_{n\to\infty } \frac {-1 x^n x n} {(n+1) x^n}\\ =&\lim_{n\to\infty } \frac {- x n} {n+1 }\\ =& -x \end{align} \]
Below is a plot the f(x) and polynomial approximation through Taylor series p(x)
library(pracma)
f <- function(x) log(1+x)
p <- taylor(f, 0, 5)
x <- seq(-1.0, 1.0, length.out=100)
yf <- f(x)
yp <- polyval(p, x)
plot(x, yf, type = "l", main =' Taylor Series Approximation of ln(1+x)',col = "blue", lwd = 3)
lines(x, yp, col = "red")
legend('topleft', inset=.05, legend= c("Poly Approximation Taylor Series", "ln(1+x)")
, lwd=c(2.5,2.5), col=c('red', 'blue'), bty='n', cex=.75)