! newtrod
!   Control:  just hit return    control break to end program
! NEWTROD  TRU   Shows newton method geometrically written by Rod Smart
! NEWTSPIR TRU   Gives a spiralling convergence picture
! NEWTCHAT TRU   Starting too far away   chatters
! NEWTON   TRU   First do split 10 ; mode 40   Show code
!                I modified code to show iterative method   x=(x+1)^(1/5)
!                Also told story about autopilots and starting guess.

open #1: screen .05,.9,.05,.9
set mode "egahires"
set window -1,3,-3,12
plot -1,0 ; 3,0
plot 0,-3 ; 0,12
plot text, at .75,10:"Newton's Method"
plot text, at .1,5:"5"
plot text, at .1,10:"10"
plot text, at 2.1,-1:"2"
for i = -1 to 3 step .01
   plot i,exp(i) -2 ;
next i
plot
let x0 = 2.5
let y0 = exp(2.5)-2
let m0 = exp(2.5)
set color "yellow"
for i = 0 to y0 step .1
   plot x0,i
next i
plot text, at x0,-1 : "x0 ="
plot text, at x0, -2 : using$("#.###",x0)
for i = -1 to 3 step .01
   plot i, y0 + m0*(i - x0);
next i
plot
let x1 = x0 - y0/m0
let y1 = exp(x1) - 2
plot text, at x1,-2 : "x1 = "
plot text, at x1,-3 : using$("#.###",x1)
get key k
for i = 0 to y1 step .1
  plot x1,i
next i
let m1 = exp(x1)
for i = -1 to 3 step .01
   plot i, y1 + m1*(i-x1);
next i
plot
let x2 = x1 - y1/m1
let y2 = exp(x2) - 2
plot text, at x2,-1 : "x2 = "
plot text, at x2,-2 : using$("#.###",x2)
get key k
for i = 0 to y2 step .1
  plot x2,i
next i
let m2 = exp(x2)
for i = -1 to 3 step .01
   plot i,y2 + m2*(i - x2);
next i
plot
let x3 = x2 - y2/m2
let y3 = exp(x3) -2
plot text, at x3,2 : "x3 = "
plot text, at x3,1 : using$("#.###",x3)
get key k
for i = 0 to y3 step .1
   plot x3,i
next i
let m3 = exp(x3)
for i = -1 to 3 step .01
   plot i, y3+m3*(i - x3);
next i
plot
let x4 = x3 - y3/m3
plot text, at .1,2 : "x4 = "
plot text, at .1,1 : using$("#.###",x4)
get key k
end
