The problem

This week, we’ll work out some Taylor Series expansions of popular functions.

• f (x) = (1−x)

• f (x) = ex

• f (x) = ln(1 + x)

• f(x)=x(1/2)

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 an R- Markdown document. Source: Apex Calculus, the calculus textbook.

Solutions:

1. First, let’s find the valid range for each given function:

\[ 1. f(x)=(1−x): \]

The function f(x) = (1−x) is defined for all real numbers x. However, for Taylor series expansion, we typically consider the convergence range. The series

\[ ∑n=0∞(−1)nxn \]

converges when

\[ ∣x∣<1∣x∣<1, \]

so the valid range for

\[ f(x)= (1−x) is −1 < x < 1. \]

\[ 2. f(x)=ex: \]

The function f(x) = ex is defined for all real numbers x For Taylor series expansion, the series

\[ ∑n=0∞n!xn \]

converges for all the x, so the valid range is

\[ −∞< x < ∞ \]

\[ 3. f(x)=ln(1+x): \]

The function\[ f(x)=ln⁡(1+x) \]

is defined as

\[ −1<x≤1 \]

because the natural logarithm function is only defined for positive numbers. Additionally, for Taylor series expansion, the series

\[ ∑n=1∞​(−1)n+1nxn​ \]

converges within the interval

\[ −1<x≤1 \]

\[ 4. f(x)=x​: \]

is defined for x >= 0>=x because the square root function is only defined for non-negative numbers. For Taylor series expansion, the series

\[ ∑n=0∞​22n(2n−1)(−1)n+1​(x−1)n \] converges for

\[ 0≤x<2. \]

2. Now, let’s compute the Taylor series expansions for the given functions within their valid ranges:

\[ 1.f(x)=(1−x) (Valid range: ∣x∣<1∣x∣<1): (1−x)=∑n=0∞(−1)nxn(1−x)=∑n=0∞​(−1)nxn \]

\[ 2. f(x)=ex: ex=∑n=0∞xnn!ex=∑n=0∞​n!xn​ \]

\[ 3. f(x)=ln(1+x) (Valid range: −1 < x ≤ 1): \]

\[ ln(1+x)=∑n=1∞​(−1)n+1nxn​ \]

\[ 4. f(x)=x​ (Valid range: 0 ≤ x): \]

\[ x​=∑n=0∞​22n(2n−1)(−1)n+1​(x−1)n \]

R code to compute the Taylor series expansions for each function:

# Function to compute the Taylor series expansion for (1 - x)
taylor_series_1_minus_x <- function(x, terms) {
  series <- rep(0, terms)
  for (n in 0:(terms-1)) {
    series[n + 1] <- (-1)^n * x^n
  }
  return(series)
}

# Function to compute the Taylor series expansion for e^x
taylor_series_exp <- function(x, terms) {
  series <- rep(0, terms)
  for (n in 0:(terms-1)) {
    series[n + 1] <- x^n / factorial(n)
  }
  return(series)
}

# Function to compute the Taylor series expansion for ln(1 + x)
taylor_series_ln <- function(x, terms) {
  series <- rep(0, terms)
  for (n in 1:terms) {
    series[n] <- (-1)^(n+1) * x^n / n
  }
  return(series)
}

# Function to compute the Taylor series expansion for sqrt(x)
taylor_series_sqrt <- function(x, terms) {
  series <- rep(0, terms)
  series[1] <- sqrt(x)
  for (n in 1:(terms-1)) {
    series[n + 1] <- (-1)^(n+1) / (2^(2*n) * (2*n - 1)) * (x - 1)^n
  }
  return(series)
}

# Number of terms to compute
terms <- 5

# Compute and print the Taylor series expansions
cat("Taylor series expansion for (1 - x):\n")
## Taylor series expansion for (1 - x):
cat(taylor_series_1_minus_x(0.5, terms), "\n")
## 1 -0.5 0.25 -0.125 0.0625
cat("\nTaylor series expansion for e^x:\n")
## 
## Taylor series expansion for e^x:
cat(taylor_series_exp(0.5, terms), "\n")
## 1 0.5 0.125 0.02083333 0.002604167
cat("\nTaylor series expansion for ln(1 + x):\n")
## 
## Taylor series expansion for ln(1 + x):
cat(taylor_series_ln(0.5, terms), "\n")
## 0.5 -0.125 0.04166667 -0.015625 0.00625
cat("\nTaylor series expansion for sqrt(x):\n")
## 
## Taylor series expansion for sqrt(x):
cat(taylor_series_sqrt(0.5, terms), "\n")
## 0.7071068 -0.125 -0.005208333 -0.000390625 -3.487723e-05