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.
use Newton’s Method to approximate all roots of the given functions accurate to 3 places after the decimal. If an interval is given, find only the roots that lie in that interval. Use technology to obtain good initial approximation.
\[f(x) = x^4 + 2x^3 -7x^2 -x + 5\]
\[f`(x) =4x^3 + 6x^2 - 14x - 1\]
\[x_{n+1} = x_n - \frac{f(x)}{f`(x_n)}\]
library(ggplot2)
val=c()
res=c()
x = -5
loop = T
i = 1
while (loop)
{
result <- x - ((x^4 + 2*x^3 - 7*x^2 -x + 5)/(4*x^3 + 6*x^2 - 14*x - 1))
val[i] <- x
res[i] <- result
if (round(x,4) == round(result,4))
{break}
else if (x>0)
{x = result}
else
{x <- x + 0.5}
i<- i+1
}
dset <- data.frame(round(val,3), round(res,3))
colnames(dset)<- c("x","f(x)")
dset
## x f(x)
## 1 -5.00 -4.253
## 2 -4.50 -3.972
## 3 -4.00 -3.762
## 4 -3.50 -3.759
## 5 -3.00 -5.154
## 6 -2.50 0.660
## 7 -2.00 -0.895
## 8 -1.50 -0.953
## 9 -1.00 -0.867
## 10 -0.50 -1.009
## 11 0.00 5.000
## 12 0.50 1.010
## 13 1.01 1.000
## 14 1.00 1.000
## 15 1.00 1.000
#plot result
plot(dset$x,dset$`f(x)`,type="l", xlab="x", ylab="f(x)")