N Selina Discussion 13

Noori Selina

Chapter 4, exercise 5. In Exercises 3 – 8, the roots of f(x) are known or are easily found. Use 5 iteratons of Newton’s Method with the given inital approximaton to approximate the root. Compare it to the known value of the root.

  1. f(x) = x^2 + x − 2, x0 = 0 To do so, first we must define the function, and the derivative
# Define the function f(x)
f <- function(x) x^2 + x - 2

# Define the derivative of f(x)
f_prime <- function(x) 2*x + 1

Next, we will perform the 5 iterations based on Newtons method

# Initial approximation
x0 <- 0

# Perform 5 iterations of Newton's Method
for (i in 1:5) {
  x_next <- x0 - f(x0) / f_prime(x0)
  cat("Iteration", i, ": x =", x_next, "\n")
  x0 <- x_next
}
## Iteration 1 : x = 2 
## Iteration 2 : x = 1.2 
## Iteration 3 : x = 1.011765 
## Iteration 4 : x = 1.000046 
## Iteration 5 : x = 1

After 5 iterations of Newton’s Method with an initial approximation \(x_0 = 0\), the method converges to an approximation of the root \(x \approx 1\), which closely matches the known value of the root.