4.1 Newton’s Method

In Exercises 8–11, use Newton’s Method to approximate all roots of the given functions accurate to 3 places after the decimal. If an interval is gven, find only the roots that lie in that interval. Use technology to obtain good initial approximations.

Exercise 4.1.8

f(x) = x3 +5x2−x−1

g <- makeFun(c^3+5*c^2-c-1 ~ c)

# get the derivative/slope of tangent
g1 <- D(g(c)~c)

plotFun(g(x) ~ x,  x.lim = range(-10,10), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

Based on the plot, start on a near guess.

# start somewhere, just like Newton
guess <- 3

# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] 0.525428
# start somewhere, just like Newton
guess <- -6

# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] -5.15633
guess <- -1

# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] -0.369102
plotFun(g(x) ~ x,  x.lim = range(-5.5,5.5), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

ladd(panel.abline(v=0.525428, col='red'))

ladd(panel.abline(v=-5.15633, col='red'))

ladd(panel.abline(v=-0.369102, col='red'))

Exercise 4.1.9

f(x) = x4 + 2x3 −7x2 − x +5

g <- makeFun(c^4+2*c^3-7*c^2-c+5 ~ c)

# get the derivative/slope of tangent
g1 <- D(g(c)~c)

plotFun(g(x) ~ x,  x.lim = range(-2,2), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

guess <- -1
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] -0.856723
guess <- 1
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] 1
guess <- 1.5
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] 1.5712
plotFun(g(x) ~ x,  x.lim = range(-2,2), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

ladd(panel.abline(v=1, col='red'))

ladd(panel.abline(v=-0.856723, col='red'))

ladd(panel.abline(v=1, col='red'))

ladd(panel.abline(v=1.5712, col='red'))

Exercise 4.1.10

f(x)=x17 −2x13 −10x8 +10 on (−2,2)

g <- makeFun(c^17+2*c^13-10*c^8+10 ~ c)

# get the derivative/slope of tangent
g1 <- D(g(c)~c)

plotFun(g(x) ~ x,  x.lim = range(-2,2), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

guess <- -1.5
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] -0.972344
guess <- 1.5
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] 1.10864
plotFun(g(x) ~ x,  x.lim = range(-2,2), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

ladd(panel.abline(v=-0.972344, col='red'))

ladd(panel.abline(v=1.10864, col='red'))

Exercise 4.1.11

f(x)=x2 cosx+(x−1)sinx on (−3,3)

g <- makeFun(c^2*cos(c) + (c-1)*sin(c) ~ c)

# get the derivative/slope of tangent
g1 <- D(g(c)~c)

plotFun(g(x) ~ x,  x.lim = range(-3, 3), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

guess <- 0
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] 0
guess <- -2
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] -2.16477
guess <- .5
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] 0.524501
guess <- 2
# find root using newton's method
options(digits=6)
roots <- (guess)
for (i in 1:10){  
  c <- roots[i]
  est <- signif(c-(g(c)/g1(c)),6)
  roots <-c(roots, est)
  }
roots[i]
## [1] 1.81328
plotFun(g(x) ~ x,  x.lim = range(-3, 3), lwd=5)

ladd(panel.abline(v=0, col='gray50'))

ladd(panel.abline(h=0, col='gray50'))

ladd(panel.abline(v=-2.16477, col='red'))

ladd(panel.abline(v=0, col='red'))

ladd(panel.abline(v=0.524501, col='red'))

ladd(panel.abline(v=1.81328, col='red'))