Problem
Using R, provide the solution for any exercise in either Chapter 4 or Chapter 7 of the calculus textbook. If you are unsure of your solution, post your concerns.
Selection
My selected problem is as follows: Page 163, Chapter #4, Exercise #6.
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.
# 6) \(f(x) = x^2 − 2, x_0 = 1.5\)
Preamble
Newton’s Method
Let \(f\) be a differentiable function on an interval \(I\) with a root in \(I\). To approximate the value of the root, accurate to \(d\) decimal places:
Choose a value \(x_0\) as an initial approximation of the root. (This is often done by looking at a graph of \(f\).)
Create successive approximations iteractevely; given an approximation \(x_n\) , compute the next approximation \(x_{n+1}\) as
\[x_{n+1}= x_n - \frac{f(x_n)}{f^l(x_n)}\]
- Stop the iterations when successive approximations do not differ in the first \(d\) places after the decimal point.
Solution
\(f(x) = x^2 − 2\)
curve(x^2-2, -4, 4, col = "red", ylab = 'f(x) = x^2 − 2')
abline(v = 0, col = 'black')
abline(v = sqrt(2), col = 'blue')
abline(v = -sqrt(2), col = 'blue')
abline(h = 0, col = 'black')
abline(h = -2, col = 'green')
\(f^l(x) = 2x\) <- first derivative.
In order to solve this, I will create a small function that iterates and find the solutions.
f <- function(x){return(x^2 -2)}
f1 <- function(x){return(2*x)}
res <- list('iteration' = 0, 'result' = 1.5)
for (i in 2:6){
res$iteration[i] <- i-1
res$result[i] <- res$result[i-1] - f(res$result[i-1])/f1(res$result[i-1])
}
res <- data.frame(res)
From the above procedure we obtain the following table:
iteration | result |
---|---|
0.000000 | 1.500000 |
1.000000 | 1.416667 |
2.000000 | 1.414216 |
3.000000 | 1.414214 |
4.000000 | 1.414214 |
5.000000 | 1.414214 |
And as we know the solution for the above will be \(x = \sqrt{2}\).
res$true_ans <- sqrt(2)
res$diff <- round(res$result - res$true_ans,6)
iteration | result | true_ans | diff |
---|---|---|---|
0.000000 | 1.500000 | 1.414214 | 0.085786 |
1.000000 | 1.416667 | 1.414214 | 0.002453 |
2.000000 | 1.414216 | 1.414214 | 0.000002 |
3.000000 | 1.414214 | 1.414214 | 0.000000 |
4.000000 | 1.414214 | 1.414214 | 0.000000 |
5.000000 | 1.414214 | 1.414214 | -0.000000 |
END