ASSIGNMENT 14 - TAYLOR SERIES

Fomba Kassoh

2024-04-28

Taylor Series Expansions of Popular Functions

Problem Statement

This week, we will 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.

The functions to explore include:

  • \(f(x) = \frac{1}{1-x}\)
  • \(f(x) = e^x\)
  • \(f(x) = \ln(1 + x)\)
  • \(f(x) = x^{1/2}\)

Function \(f(x) = \frac{1}{1-x}\)

The Taylor series expansion of \(f(x) = \frac{1}{1-x}\) around \(x = 0\) is:

fx <- function(x) 1/(1 - x)
taylor_series_1x <- taylor(fx, x0 = 0, n = 7)
print(taylor_series_1x)
## [1] 1.007014 1.001710 1.000293 1.000029 1.000003 1.000000 1.000000 1.000000

Function \(f(x) = e^x\)

The Taylor series expansion for \(f(x) = e^x\) around \(x = 0\).

ex <- function(x) exp(x)
taylor_series_ex <- taylor(ex, x0 = 0, n = 8) 
print(taylor_series_ex)
## [1] 2.505533e-05 1.961045e-04 1.386346e-03 8.334245e-03 4.166657e-02
## [6] 1.666667e-01 5.000000e-01 1.000000e+00 1.000000e+00

Function \(f(x) = \ln(1 + x)\)

For \(f(x) = \ln(1 + x)\), the expansion is valid for \(-1 < x \leq 1\).

ln1x <- function(x) log(1 + x)
taylor_series_ln1x <- taylor(ln1x, x0 = 0, n = 6)
print(taylor_series_ln1x)
## [1] -0.1668792  0.2000413 -0.2500044  0.3333339 -0.5000000  1.0000000  0.0000000

Function \(f(x) = x^{1/2}\)

The Taylor series expansion for \(f(x) = x^{1/2}\) around \(x = 1\).

# Manually computing derivatives and Taylor series coefficients because having issues with 'taylor()' function
f <- function(x) sqrt(x)
f1 <- function(x) (1/2) * x^(-1/2)
f2 <- function(x) -(1/4) * x^(-3/2)
f3 <- function(x) (3/8) * x^(-5/2)
f4 <- function(x) -(15/16) * x^(-7/2)
f5 <- function(x) (105/32) * x^(-9/2)
f6 <- function(x) -(945/64) * x^(-11/2)

x0 <- 1 # Easier since sqrt(1) = 1

taylor_series_sqrtx <- c(f(x0), f1(x0), f2(x0)/factorial(2), f3(x0)/factorial(3), f4(x0)/factorial(4), f5(x0)/factorial(5), f6(x0)/factorial(6))

print(taylor_series_sqrtx)
## [1]  1.00000000  0.50000000 -0.12500000  0.06250000 -0.03906250  0.02734375
## [7] -0.02050781