Newton-type iterations for solution of R(z)=0 from Example~\ref {ex:num-newton-fifth-root}. Left: exact Newton method. Right: constant Jacobian approximation.
# [makes] Newton_Type_Solver.mat# Generate figure for Example 8.5.importnumpyasnpfromscipy.ioimportsavematz0=2.0# Initial guess.Mk=5*z0**4# Inexact Jacobian.iter1=10# Number of iterations for exact Jacobian solver.iter2=100# Number of iterations for inexact Jacobian solver.# Exact Jacobian Newton's method on R(z) = z^5 - 2.zk1=np.zeros(iter1+1)zk1[0]=z0dashline1=np.zeros((2*iter1+1,2))dashline1[0]=[z0,0]foriinrange(iter1):zk1[i+1]=zk1[i]-(zk1[i]**5-2)/(5*zk1[i]**4)dashline1[2*i+1]=[zk1[i],zk1[i]**5-2]dashline1[2*i+2]=[zk1[i+1],0]# Inexact Jacobian Newton's method.zk2=np.zeros(iter2+1)zk2[0]=z0dashline2=np.zeros((2*iter2+1,2))dashline2[0]=[z0,0]foriinrange(iter2):zk2[i+1]=zk2[i]-(zk2[i]**5-2)/Mkdashline2[2*i+1]=[zk2[i],zk2[i]**5-2]dashline2[2*i+2]=[zk2[i+1],0]ztrue=2**(1/5)z=np.arange(1.0,2.16,0.01)R=z**5-2savemat('Newton_Type_Solver.mat',{'z':z,'R':R,'zk1':zk1,'zk2':zk2,'dashline1':dashline1,'dashline2':dashline2,'ztrue':ztrue,})