Solving these manually, I can go with:
\[ \begin{aligned} f(x) &= \frac{1}{1-x}, \\ f'(x) &= \frac{1}{(1-x)^2}, \\ f''(x) &= \frac{2}{(1-x)^3}, \\ f'''(x) &= \frac{6}{(1-x)^4}, \\ f^{(4)}(x) &= \frac{24}{(1-x)^5}, \\ \text{Taylor Series: } P(x) &= \sum_{n=0}^\infty \frac{f^{(n)}(0)}{n!} x^n = 1 + x + x^2 + x^3 + x^4 + \cdots. \end{aligned} \]
\[ \begin{aligned} f(x) &= e^x, \\ f'(x) &= e^x, \\ f''(x) &= e^x, \\ f'''(x) &= e^x, \\ f^{(4)}(x) &= e^x, \\ \text{Taylor Series: } P(x) &= \sum_{n=0}^\infty \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \cdots. \end{aligned} \]
\[ \begin{aligned} f(x) &= \ln(1+x), \\ f'(x) &= \frac{1}{1+x}, \\ f''(x) &= -\frac{1}{(1+x)^2}, \\ f'''(x) &= \frac{2}{(1+x)^3}, \\ f^{(4)}(x) &= -\frac{6}{(1+x)^4}, \\ \text{Taylor Series: } P(x) &= \ln(1) + \frac{1}{1}x - \frac{1}{2}x^2 + \frac{1}{3}x^3 - \frac{1}{4}x^4 + \cdots. \end{aligned} \]
\[ \begin{aligned} f(x) &= x^{1/2}, \\ f'(x) &= \frac{1}{2}x^{-1/2}, \\ f''(x) &= -\frac{1}{4}x^{-3/2}, \\ f'''(x) &= \frac{3}{8}x^{-5/2}, \\ f^{(4)}(x) &= -\frac{15}{16}x^{-7/2}, \\ \text{Taylor Series: } P(x) &= 1 + \frac{1}{2}(x-1) - \frac{1}{8}(x-1)^2 + \frac{1}{16}(x-1)^3 - \frac{5}{128}(x-1)^4 + \cdots. \end{aligned} \]
Using R, I’ll use the taylor function from the pracma package
library(pracma)
# functions
f1 <- function(x) 1 / (1 - x)
f2 <- function(x) exp(x)
f3 <- function(x) log(1 + x)
f4 <- function(x) {ifelse(x < 0, NA, sqrt(x))}
# Taylor series at specified points
taylor_f1 <- taylor(f1, x0 = 0, n = 5)
taylor_f2 <- taylor(f2, x0 = 0, n = 5)
taylor_f3 <- taylor(f3, x0 = 0, n = 5)
# output
print("Taylor series for 1/(1-x) expanded at x=0:")
## [1] "Taylor series for 1/(1-x) expanded at x=0:"
print(taylor_f1)
## [1] 1.000293 1.000029 1.000003 1.000000 1.000000 1.000000
print("Taylor series for e^x expanded at x=0:")
## [1] "Taylor series for e^x expanded at x=0:"
print(taylor_f2)
## [1] 0.008334245 0.041666573 0.166666726 0.499999996 1.000000000 1.000000000
print("Taylor series for ln(1+x) expanded at x=0:")
## [1] "Taylor series for ln(1+x) expanded at x=0:"
print(taylor_f3)
## [1] 0.2000413 -0.2500044 0.3333339 -0.5000000 1.0000000 0.0000000
# For the square root function (#4), manually defined derivatives at x = 1
sqrt_x_at_1 = 1
first_derivative_at_1 = 1/2
second_derivative_at_1 = -1/4
third_derivative_at_1 = 3/8
# the Taylor polynomial function for square root
taylor_sqrt_x <- function(x, order = 3) {
terms <- c(sqrt_x_at_1,
first_derivative_at_1 * (x - 1),
second_derivative_at_1 * (x - 1)^2 / factorial(2),
third_derivative_at_1 * (x - 1)^3 / factorial(3))
sum(terms[1:(order + 1)])}
# testing the square root Taylor series and explain the output
test_point <- 1.05
result <- taylor_sqrt_x(test_point)
print(paste("Testing Taylor series for sqrt(x) at x =", test_point, ":"))
## [1] "Testing Taylor series for sqrt(x) at x = 1.05 :"
print(paste("Approximate value using Taylor series:", result))
## [1] "Approximate value using Taylor series: 1.0246953125"
print(paste("Exact value using sqrt function:", sqrt(test_point)))
## [1] "Exact value using sqrt function: 1.02469507659596"