4.1 problem 5

The roots of f(x) are known or are easily found. Use 5 iterations of Newton’s Method with the given initial approximation to approximate the root. Compare it to the known value of the root. \(f(x) = x^2 + x - 2\) initial \(x_0 = 0\)

We use Newton’s Method to approximate the roots of the function \(f(x) = x^2 + x - 2\) with an initial guess of \(x_0 = 0\). Newton’s method uses the formula:

\[ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} \]

to converge to the roots of a given function.

Define the function and its derivative

f <- function(x) {
  x^2 + x - 2
}

df <- function(x) {
  2 * x + 1
}

Newton’s Method Iteration

We will now perform 5 iterations of Newton’s method.

x_new <- 0 
iterations <- 5

# Newton's method iterations
for (i in 1:iterations) {
  x_new <- x_new - f(x_new) / df(x_new)
  print(paste("Iteration", i, ": x =", x_new))
}
## [1] "Iteration 1 : x = 2"
## [1] "Iteration 2 : x = 1.2"
## [1] "Iteration 3 : x = 1.01176470588235"
## [1] "Iteration 4 : x = 1.00004577706569"
## [1] "Iteration 5 : x = 1.00000000069849"

These approximations indicate the method converging slowly towards the root \(x = 1\). The actual roots of the equation, found by factoring/the quadratic formula, are \(x = -2\) and \(x = 1\). Since initial guess 0 is closer to 1 than to -2, the iterations move towards 1.