381 - A4 - Newton's

443 days ago by Professor381

f = x^2 - 16 fp = 2*x exact = 4 # f = tan(x/4)-1 # fp = sec(x/4)^2/4 # exact = pi (plot(f,(x,0,5))+plot(fp,(x,0,5),color='green')).show() 
       
x0 = 20 points = plot(f,(x,0,5)) points += point((x0,0),color='red',size=40) show(points) 
       
p = x0 errors = [] for k in range(6): fx = f(x=p) fxp = fp(x=p) p = p - fx/fxp points += point((p,0),color='red',size=40) errors.append(n(abs(p-exact)/exact)) end show(points) pretty_print((p,fx)) pretty_print(' or ',(n(p),n(fx))) pretty_print(errors) 
       

                                
                            

                                

Experimentally determine the rate of convergence

# Experiment with r to see if there is a (relatively) constant value for the following ratio of successive error terms r = 2 for k in range(len(errors)-1): errors[k+1]/errors[k]^r 
       
0.192307692307692
0.335051546391753
0.462446824116180
0.498479875456300
0.499997682185350
0.192307692307692
0.335051546391753
0.462446824116180
0.498479875456300
0.499997682185350