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.
Problem: use Newton’s Method to approximate when the given functions are equal, accurate to three decimal places after the decimal. Use technology to obtain good initial approximations.
Solution: Using the plot below, we can estimate that the functions are equal in two spots, at approximately x = .8 and x = -.8
equation1<-function(x){x^2}
equation2<-function(x){cos(x)}
x<-seq(-2,2,by=.25)
plot(x, equation1(x), type = "l")
lines(x,equation2(x), type = "l")
Using Newton’s method, we find the following:
Let \(y(x) = cos(x)-x^2 = 0\). Then \(y'(x) = -sin(x) - 2x\). Let’s start with \(x_0=.8\).
Then \(x_1 = .8 - (cos(.8)-(.8)^2)/(-sin(.8) - 2*(.8)) = 0.8244704\).
So \(x_2 = 0.8244704 - (cos(0.8244704)-(0.8244704)^2)/(-sin(0.8244704) - 2*(0.8244704)) = 0.8241324\)
Then \(x_3 = 0.8241324 - (cos(0.8241324)-(0.8241324)^2)/(-sin(0.8241324) - 2*(0.8241324)) = 0.8241323\).
Since this has not changed beyond three decimal places, we can say that the two functions are equal when x = 0.824, and also when x = -0.824.
We can automate this process too.
equation3<-function(x){cos(x)-x^2}
equation4<-function(x){-sin(x) - 2*x}
start<-0.8
prevValue<-0
while(start - prevValue>=0.001){
prevValue<-start
start<-start - equation3(start)/equation4(start)
}
#show value
start
## [1] 0.8241324
Replotting, we can see that this is correct.
equation1<-function(x){x^2}
equation2<-function(x){cos(x)}
x<-seq(-2,2,by=.25)
plot(x, equation1(x), type = "l")
lines(x,equation2(x), type = "l")
lines(0.8241323,0.8241323^2, type = "p")
lines(-0.8241323,(-0.8241323)^2, type = "p")