Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168756
Image: ubuntu2004
a = ComplexField()
TOL = 10^(-10) f_(x) = x^4 - 1 def newton_method(p_0, TOL, max, zeros): var('i') var('p') f_1(x) = derivative(f_,x) temporary = [] values = [] i = 1 temporary1 = (0, p_0, f_(p_0), abs(zeros-p_0), (abs(zeros-p_0))/(abs(p_0))) values.append(temporary1) while i <= max: p = n(p_0 - f_(p_0)/f_1(p_0)) temporary2 = (i, p, f_(p), abs(zeros-p), (abs(zeros-p))/(abs(p))) values.append(temporary2) if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
w = newton_method(.5, TOL, 50, 1) ex = newton_method(.5, TOL, 50, -1) y = newton_method(.5, TOL, 50, a(0,1)) z = newton_method(.5, TOL, 50, a(0,-1))
1.00000000000000 9 done 1.00000000000000 9 done 1.00000000000000 9 done 1.00000000000000 9 done
matw=matrix(w) matex=matrix(ex) maty=matrix(y) matz=matrix(z)
latex(matw)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 1 & 2.37500000000000 & 30.8166503906250 & 1.37500000000000 & 0.578947368421053 \\ 2 & 1.79991161247995 & 9.49553824779953 & 0.799911612479953 & 0.444417163006032 \\ 3 & 1.39280696583296 & 2.76325563488009 & 0.392806965832955 & 0.282025417354257 \\ 4 & 1.13713195528050 & 0.672027655272641 & 0.137131955280504 & 0.120594584158596 \\ 5 & 1.02287186525853 & 0.0946743271371449 & 0.0228718652585267 & 0.0223604402812917 \\ 6 & 1.00075576570494 & 0.00302649163762347 & 0.000755765704943512 & 0.000755194954496357 \\ 7 & 1.00000085569472 & 3.42278329013013 \times 10^{-6} & 8.55694724188893 \times 10^{-7} & 8.55693991976059 \times 10^{-7} \\ 8 & 1.00000000000110 & 4.39293046383682 \times 10^{-12} & 1.09823261595920 \times 10^{-12} & 1.09823261595800 \times 10^{-12} \\ 9 & 1.00000000000000 & 0 & 0.000000000000000 & 0.000000000000000 \end{array}\right)
latex(matex)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.50000000000000 & 3.00000000000000 \\ 1 & 2.37500000000000 & 30.8166503906250 & 3.37500000000000 & 1.42105263157895 \\ 2 & 1.79991161247995 & 9.49553824779953 & 2.79991161247995 & 1.55558283699397 \\ 3 & 1.39280696583296 & 2.76325563488009 & 2.39280696583296 & 1.71797458264574 \\ 4 & 1.13713195528050 & 0.672027655272641 & 2.13713195528050 & 1.87940541584140 \\ 5 & 1.02287186525853 & 0.0946743271371449 & 2.02287186525853 & 1.97763955971871 \\ 6 & 1.00075576570494 & 0.00302649163762347 & 2.00075576570494 & 1.99924480504550 \\ 7 & 1.00000085569472 & 3.42278329013013 \times 10^{-6} & 2.00000085569472 & 1.99999914430601 \\ 8 & 1.00000000000110 & 4.39293046383682 \times 10^{-12} & 2.00000000000110 & 1.99999999999890 \\ 9 & 1.00000000000000 & 0 & 2.00000000000000 & 2.00000000000000 \end{array}\right)
latex(maty)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 2.37500000000000 & 30.8166503906250 & 2.57694101601104 & 1.08502779621517 \\ 2 & 1.79991161247995 & 9.49553824779953 & 2.05904876405106 & 1.14397215384041 \\ 3 & 1.39280696583296 & 2.76325563488009 & 1.71461693799892 & 1.23105138045710 \\ 4 & 1.13713195528050 & 0.672027655272641 & 1.51428830931235 & 1.33167334035461 \\ 5 & 1.02287186525853 & 0.0946743271371449 & 1.43047784070130 & 1.39849172637059 \\ 6 & 1.00075576570494 & 0.00302649163762347 & 1.41474807036154 & 1.41367965975691 \\ 7 & 1.00000085569472 & 3.42278329013013 \times 10^{-6} & 1.41421416744077 & 1.41421295730620 \\ 8 & 1.00000000000110 & 4.39293046383682 \times 10^{-12} & 1.41421356237387 & 1.41421356237232 \\ 9 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \end{array}\right)
latex(matz)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 2.37500000000000 & 30.8166503906250 & 2.57694101601104 & 1.08502779621517 \\ 2 & 1.79991161247995 & 9.49553824779953 & 2.05904876405106 & 1.14397215384041 \\ 3 & 1.39280696583296 & 2.76325563488009 & 1.71461693799892 & 1.23105138045710 \\ 4 & 1.13713195528050 & 0.672027655272641 & 1.51428830931235 & 1.33167334035461 \\ 5 & 1.02287186525853 & 0.0946743271371449 & 1.43047784070130 & 1.39849172637059 \\ 6 & 1.00075576570494 & 0.00302649163762347 & 1.41474807036154 & 1.41367965975691 \\ 7 & 1.00000085569472 & 3.42278329013013 \times 10^{-6} & 1.41421416744077 & 1.41421295730620 \\ 8 & 1.00000000000110 & 4.39293046383682 \times 10^{-12} & 1.41421356237387 & 1.41421356237232 \\ 9 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \end{array}\right)
TOL = 10^(-10) f_(x) = x^4 - 1 def newton_method_graph(p_0, TOL, max, zeros): var('i') var('p') f_1(x) = derivative(f_,x) temporary = [] values = [] i = 1 while i <= max: p = n(p_0 - f_(p_0)/f_1(p_0)) temporary2 = (p.real(),p.imag()) values.append(temporary2) if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
gw = newton_method_graph(.5, TOL, 50, 1) gex = newton_method_graph(-.5, TOL, 50, -1) gy = newton_method_graph(a(0,.5), TOL, 50, a(0,1)) gz = newton_method_graph(a(0,-.5), TOL, 50, a(0,-1))
1.00000000000000 9 done -1.00000000000000 9 done 1.00000000000000*I 9 done -1.00000000000000*I 9 done
graph1 = point(gw,rgbcolor=(1,0,0)) graph2 = point(gex,rgbcolor=(0,1,0)) graph3 = point(gy,rgbcolor=(0,0,1)) graph4 = point(gz,rgbcolor=(0,.5,.5)) graph = graph1+graph2+graph3+graph4 graph.show(xmax=2,xmin=-2,ymax=2,ymin=-2)
def newton_method2(p_0, TOL, max, zeros): var('i') var('p') k = p_0 f_(x) = x^4 - 1 f_1(x) = derivative(f_,x) temporary = [] values = [] i = 1 temporary1 = (0, p_0, f_(p_0), abs(zeros-p_0), (abs(zeros-p_0))/(abs(p_0))) values.append(temporary1) while i <= max: p = p_0 - ((f_(p_0))/(f_1(k))) temporary2 = (i, p, f_(p), abs(zeros-p), (abs(zeros-p))/(abs(p))) values.append(temporary2) if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
w = newton_method2(.5, TOL, 50, 1) ex = newton_method2(.5, TOL, 50, -1) y = newton_method2(.5, TOL, 50, a(0,1)) z = newton_method2(.5, TOL, 50, a(0,-1))
-infinity 17 done -infinity 17 done -infinity 17 done -infinity 17 done
matw=matrix(w) matex=matrix(ex) maty=matrix(y) matz=matrix(z)
latex(matw)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 1 & 2.37500000000000 & 30.8166503906250 & 1.37500000000000 & 0.578947368421053 \\ 2 & -59.2583007812500 & 1.23309557953672 \times 10^{7} & 60.2583007812500 & 1.01687527294600 \\ 3 & -2.46619708490352 \times 10^{7} & 3.69922817575396 \times 10^{29} & 2.46619718490352 \times 10^{7} & 1.00000004054826 \\ 4 & -7.39845635150792 \times 10^{29} & 2.99615628913433 \times 10^{119} & 7.39845635150792 \times 10^{29} & 1.00000000000000 \\ 5 & -5.99231257826866 \times 10^{119} & 1.28937082155825 \times 10^{479} & 5.99231257826866 \times 10^{119} & 1.00000000000000 \\ 6 & -2.57874164311650 \times 10^{479} & 4.42212825522238 \times 10^{1917} & 2.57874164311650 \times 10^{479} & 1.00000000000000 \\ 7 & -8.84425651044475 \times 10^{1917} & 6.11850500769736 \times 10^{7671} & 8.84425651044475 \times 10^{1917} & 1.00000000000000 \\ 8 & -1.22370100153947 \times 10^{7672} & 2.24233895592048 \times 10^{30688} & 1.22370100153947 \times 10^{7672} & 1.00000000000000 \\ 9 & -4.48467791184097 \times 10^{30688} & 4.04506058288990 \times 10^{122754} & 4.48467791184097 \times 10^{30688} & 1.00000000000000 \\ 10 & -8.09012116577980 \times 10^{122754} & 4.28371041644273 \times 10^{491019} & 8.09012116577980 \times 10^{122754} & 1.00000000000000 \\ 11 & -8.56742083288546 \times 10^{491019} & 5.38766272052476 \times 10^{1964079} & 8.56742083288546 \times 10^{491019} & 1.00000000000000 \\ 12 & -1.07753254410495 \times 10^{1964080} & 1.34809836856594 \times 10^{7856320} & 1.07753254410495 \times 10^{1964080} & 1.00000000000000 \\ 13 & -2.69619673713187 \times 10^{7856320} & 5.28452936046516 \times 10^{31425281} & 2.69619673713187 \times 10^{7856320} & 1.00000000000000 \\ 14 & -1.05690587209303 \times 10^{31425282} & 1.24780075268846 \times 10^{125701128} & 1.05690587209303 \times 10^{31425282} & 1.00000000000000 \\ 15 & -2.49560150537692 \times 10^{125701128} & +infinity & 2.49560150537692 \times 10^{125701128} & 1.00000000000000 \\ 16 & -infinity & +infinity & +infinity & NaN \\ 17 & -infinity & +infinity & +infinity & NaN \end{array}\right)
latex(matex)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.50000000000000 & 3.00000000000000 \\ 1 & 2.37500000000000 & 30.8166503906250 & 3.37500000000000 & 1.42105263157895 \\ 2 & -59.2583007812500 & 1.23309557953672 \times 10^{7} & 58.2583007812500 & 0.983124727053996 \\ 3 & -2.46619708490352 \times 10^{7} & 3.69922817575396 \times 10^{29} & 2.46619698490352 \times 10^{7} & 0.999999959451740 \\ 4 & -7.39845635150792 \times 10^{29} & 2.99615628913433 \times 10^{119} & 7.39845635150792 \times 10^{29} & 1.00000000000000 \\ 5 & -5.99231257826866 \times 10^{119} & 1.28937082155825 \times 10^{479} & 5.99231257826866 \times 10^{119} & 1.00000000000000 \\ 6 & -2.57874164311650 \times 10^{479} & 4.42212825522238 \times 10^{1917} & 2.57874164311650 \times 10^{479} & 1.00000000000000 \\ 7 & -8.84425651044475 \times 10^{1917} & 6.11850500769736 \times 10^{7671} & 8.84425651044475 \times 10^{1917} & 1.00000000000000 \\ 8 & -1.22370100153947 \times 10^{7672} & 2.24233895592048 \times 10^{30688} & 1.22370100153947 \times 10^{7672} & 1.00000000000000 \\ 9 & -4.48467791184097 \times 10^{30688} & 4.04506058288990 \times 10^{122754} & 4.48467791184097 \times 10^{30688} & 1.00000000000000 \\ 10 & -8.09012116577980 \times 10^{122754} & 4.28371041644273 \times 10^{491019} & 8.09012116577980 \times 10^{122754} & 1.00000000000000 \\ 11 & -8.56742083288546 \times 10^{491019} & 5.38766272052476 \times 10^{1964079} & 8.56742083288546 \times 10^{491019} & 1.00000000000000 \\ 12 & -1.07753254410495 \times 10^{1964080} & 1.34809836856594 \times 10^{7856320} & 1.07753254410495 \times 10^{1964080} & 1.00000000000000 \\ 13 & -2.69619673713187 \times 10^{7856320} & 5.28452936046516 \times 10^{31425281} & 2.69619673713187 \times 10^{7856320} & 1.00000000000000 \\ 14 & -1.05690587209303 \times 10^{31425282} & 1.24780075268846 \times 10^{125701128} & 1.05690587209303 \times 10^{31425282} & 1.00000000000000 \\ 15 & -2.49560150537692 \times 10^{125701128} & +infinity & 2.49560150537692 \times 10^{125701128} & 1.00000000000000 \\ 16 & -infinity & +infinity & +infinity & NaN \\ 17 & -infinity & +infinity & +infinity & NaN \end{array}\right)
latex(maty)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 2.37500000000000 & 30.8166503906250 & 2.57694101601104 & 1.08502779621517 \\ 2 & -59.2583007812500 & 1.23309557953672 \times 10^{7} & 59.2667378171019 & 1.00014237728286 \\ 3 & -2.46619708490352 \times 10^{7} & 3.69922817575396 \times 10^{29} & 2.46619708490353 \times 10^{7} & 1.00000000000000 \\ 4 & -7.39845635150792 \times 10^{29} & 2.99615628913433 \times 10^{119} & 7.39845635150792 \times 10^{29} & 1.00000000000000 \\ 5 & -5.99231257826866 \times 10^{119} & 1.28937082155825 \times 10^{479} & 5.99231257826866 \times 10^{119} & 1.00000000000000 \\ 6 & -2.57874164311650 \times 10^{479} & 4.42212825522238 \times 10^{1917} & 2.57874164311650 \times 10^{479} & 1.00000000000000 \\ 7 & -8.84425651044475 \times 10^{1917} & 6.11850500769736 \times 10^{7671} & 8.84425651044475 \times 10^{1917} & 1.00000000000000 \\ 8 & -1.22370100153947 \times 10^{7672} & 2.24233895592048 \times 10^{30688} & 1.22370100153947 \times 10^{7672} & 1.00000000000000 \\ 9 & -4.48467791184097 \times 10^{30688} & 4.04506058288990 \times 10^{122754} & 4.48467791184097 \times 10^{30688} & 1.00000000000000 \\ 10 & -8.09012116577980 \times 10^{122754} & 4.28371041644273 \times 10^{491019} & 8.09012116577980 \times 10^{122754} & 1.00000000000000 \\ 11 & -8.56742083288546 \times 10^{491019} & 5.38766272052476 \times 10^{1964079} & 8.56742083288546 \times 10^{491019} & 1.00000000000000 \\ 12 & -1.07753254410495 \times 10^{1964080} & 1.34809836856594 \times 10^{7856320} & 1.07753254410495 \times 10^{1964080} & 1.00000000000000 \\ 13 & -2.69619673713187 \times 10^{7856320} & 5.28452936046516 \times 10^{31425281} & 2.69619673713187 \times 10^{7856320} & 1.00000000000000 \\ 14 & -1.05690587209303 \times 10^{31425282} & 1.24780075268846 \times 10^{125701128} & 1.05690587209303 \times 10^{31425282} & 1.00000000000000 \\ 15 & -2.49560150537692 \times 10^{125701128} & +infinity & 2.49560150537692 \times 10^{125701128} & 1.00000000000000 \\ 16 & -infinity & +infinity & +infinity & NaN \\ 17 & -infinity & +infinity & +infinity & NaN \end{array}\right)
latex(matz)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 2.37500000000000 & 30.8166503906250 & 2.57694101601104 & 1.08502779621517 \\ 2 & -59.2583007812500 & 1.23309557953672 \times 10^{7} & 59.2667378171019 & 1.00014237728286 \\ 3 & -2.46619708490352 \times 10^{7} & 3.69922817575396 \times 10^{29} & 2.46619708490353 \times 10^{7} & 1.00000000000000 \\ 4 & -7.39845635150792 \times 10^{29} & 2.99615628913433 \times 10^{119} & 7.39845635150792 \times 10^{29} & 1.00000000000000 \\ 5 & -5.99231257826866 \times 10^{119} & 1.28937082155825 \times 10^{479} & 5.99231257826866 \times 10^{119} & 1.00000000000000 \\ 6 & -2.57874164311650 \times 10^{479} & 4.42212825522238 \times 10^{1917} & 2.57874164311650 \times 10^{479} & 1.00000000000000 \\ 7 & -8.84425651044475 \times 10^{1917} & 6.11850500769736 \times 10^{7671} & 8.84425651044475 \times 10^{1917} & 1.00000000000000 \\ 8 & -1.22370100153947 \times 10^{7672} & 2.24233895592048 \times 10^{30688} & 1.22370100153947 \times 10^{7672} & 1.00000000000000 \\ 9 & -4.48467791184097 \times 10^{30688} & 4.04506058288990 \times 10^{122754} & 4.48467791184097 \times 10^{30688} & 1.00000000000000 \\ 10 & -8.09012116577980 \times 10^{122754} & 4.28371041644273 \times 10^{491019} & 8.09012116577980 \times 10^{122754} & 1.00000000000000 \\ 11 & -8.56742083288546 \times 10^{491019} & 5.38766272052476 \times 10^{1964079} & 8.56742083288546 \times 10^{491019} & 1.00000000000000 \\ 12 & -1.07753254410495 \times 10^{1964080} & 1.34809836856594 \times 10^{7856320} & 1.07753254410495 \times 10^{1964080} & 1.00000000000000 \\ 13 & -2.69619673713187 \times 10^{7856320} & 5.28452936046516 \times 10^{31425281} & 2.69619673713187 \times 10^{7856320} & 1.00000000000000 \\ 14 & -1.05690587209303 \times 10^{31425282} & 1.24780075268846 \times 10^{125701128} & 1.05690587209303 \times 10^{31425282} & 1.00000000000000 \\ 15 & -2.49560150537692 \times 10^{125701128} & +infinity & 2.49560150537692 \times 10^{125701128} & 1.00000000000000 \\ 16 & -infinity & +infinity & +infinity & NaN \\ 17 & -infinity & +infinity & +infinity & NaN \end{array}\right)
def newton_method2_graph(p_0, TOL, max, zeros): var('i') var('p') k = p_0 f_(x) = x^4 - 1 f_1(x) = derivative(f_,x) temporary = [] values = [] i = 1 while i <= max: p = p_0 - ((f_(p_0))/(f_1(k))) temporary2 = (p.real(),p.imag()) values.append(temporary2) if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
gw = newton_method2_graph(.5, TOL, 50, 1) gex = newton_method2_graph(-.5, TOL, 50, -1) gy = newton_method2_graph(a(0,.5), TOL, 50, a(0,1)) gz = newton_method2_graph(a(0,-.5), TOL, 50, a(0,-1))
-infinity 17 done +infinity 17 done NaN - NaN*I 16 done NaN - NaN*I 16 done
graph1 = point(gw,rgbcolor=(1,0,0)) graph2 = point(gex,rgbcolor=(0,1,0)) graph3 = point(gy,rgbcolor=(0,0,1)) graph4 = point(gz,rgbcolor=(0,.5,.5)) graph = graph1+graph2+graph3+graph4 graph.show(xmax=5,xmin=-5,ymax=5,ymin=-5)
def mod_newton_method(p_0, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 f_1(x) = derivative(f_,x) mu_(x) = f_(x)/f_1(x) mu_1(x) = derivative(mu_,x) temporary = [] values = [] i = 1 temporary1 = (0, p_0, f_(p_0), abs(zeros-p_0), (abs(zeros-p_0))/(abs(p_0))) values.append(temporary1) while i <= max: p = p_0 - n(mu_(p_0)/mu_1(p_0)) temporary2 = (i, p, f_(p), abs(zeros-p), (abs(zeros-p))/(abs(p))) values.append(temporary2) if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
w = mod_newton_method(.5, TOL, 50, 1) ex = mod_newton_method(.5, TOL, 50, -1) y = mod_newton_method(.5, TOL, 50, a(0,1)) z = mod_newton_method(.5, TOL, 50, a(0,-1))
1.00000000000000 8 done 1.00000000000000 8 done 1.00000000000000 8 done 1.00000000000000 8 done
matw=matrix(w) matex=matrix(ex) maty=matrix(y) matz=matrix(z)
latex(matw)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 1 & 0.653061224489796 & -0.818107164497092 & 0.346938775510204 & 0.531250000000000 \\ 2 & 0.820971991517844 & -0.545730725340175 & 0.179028008482156 & 0.218068351090957 \\ 3 & 0.950675151518051 & -0.183175848382037 & 0.0493248484819490 & 0.0518840199022625 \\ 4 & 0.996299660402282 & -0.0147194057923515 & 0.00370033959771821 & 0.00371408296598646 \\ 5 & 0.999979436178562 & -0.0000822527485641045 & 0.0000205638214384463 & 0.0000205642443178944 \\ 6 & 0.999999999365690 & -2.53724197207816 \times 10^{-9} & 6.34310493019541 \times 10^{-10} & 6.34310493421891 \times 10^{-10} \\ 7 & 1.00000000000000 & 0 & 0.000000000000000 & 0.000000000000000 \\ 8 & 1.00000000000000 & 0 & 0.000000000000000 & 0.000000000000000 \end{array}\right)
latex(matex)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.50000000000000 & 3.00000000000000 \\ 1 & 0.653061224489796 & -0.818107164497092 & 1.65306122448980 & 2.53125000000000 \\ 2 & 0.820971991517844 & -0.545730725340175 & 1.82097199151784 & 2.21806835109096 \\ 3 & 0.950675151518051 & -0.183175848382037 & 1.95067515151805 & 2.05188401990226 \\ 4 & 0.996299660402282 & -0.0147194057923515 & 1.99629966040228 & 2.00371408296599 \\ 5 & 0.999979436178562 & -0.0000822527485641045 & 1.99997943617856 & 2.00002056424432 \\ 6 & 0.999999999365690 & -2.53724197207816 \times 10^{-9} & 1.99999999936569 & 2.00000000063431 \\ 7 & 1.00000000000000 & 0 & 2.00000000000000 & 2.00000000000000 \\ 8 & 1.00000000000000 & 0 & 2.00000000000000 & 2.00000000000000 \end{array}\right)
latex(maty)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 0.653061224489796 & -0.818107164497092 & 1.19435713374690 & 1.82885936104994 \\ 2 & 0.820971991517844 & -0.545730725340175 & 1.29382959111962 & 1.57597287664777 \\ 3 & 0.950675151518051 & -0.183175848382037 & 1.37977651948200 & 1.45136487187948 \\ 4 & 0.996299660402282 & -0.0147194057923515 & 1.41159945215266 & 1.41684224963270 \\ 5 & 0.999979436178562 & -0.0000822527485641045 & 1.41419902163026 & 1.41422810356446 \\ 6 & 0.999999999365690 & -2.53724197207816 \times 10^{-9} & 1.41421356192457 & 1.41421356282162 \\ 7 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \\ 8 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \end{array}\right)
latex(matz)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 0.653061224489796 & -0.818107164497092 & 1.19435713374690 & 1.82885936104994 \\ 2 & 0.820971991517844 & -0.545730725340175 & 1.29382959111962 & 1.57597287664777 \\ 3 & 0.950675151518051 & -0.183175848382037 & 1.37977651948200 & 1.45136487187948 \\ 4 & 0.996299660402282 & -0.0147194057923515 & 1.41159945215266 & 1.41684224963270 \\ 5 & 0.999979436178562 & -0.0000822527485641045 & 1.41419902163026 & 1.41422810356446 \\ 6 & 0.999999999365690 & -2.53724197207816 \times 10^{-9} & 1.41421356192457 & 1.41421356282162 \\ 7 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \\ 8 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \end{array}\right)
def mod_newton_method_graph(p_0, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 f_1(x) = derivative(f_,x) mu_(x) = f_(x)/f_1(x) mu_1(x) = derivative(mu_,x) temporary = [] values = [] i = 1 while i <= max: p = p_0 - n(mu_(p_0)/mu_1(p_0)) temporary2 = (p.real(),p.imag()) values.append(temporary2) if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
gw = mod_newton_method_graph(.5, TOL, 50, 1) gex = mod_newton_method_graph(-.5, TOL, 50, -1) gy = mod_newton_method_graph(a(0,.5), TOL, 50, a(0,1)) gz = mod_newton_method_graph(a(0,-.5), TOL, 50, a(0,-1))
1.00000000000000 8 done -1.00000000000000 8 done 1.00000000000000*I 8 done -1.00000000000000*I 8 done
graph1 = point(gw,rgbcolor=(1,0,0)) graph2 = point(gex,rgbcolor=(0,1,0)) graph3 = point(gy,rgbcolor=(0,0,1)) graph4 = point(gz,rgbcolor=(0,.5,.5)) graph = graph1+graph2+graph3+graph4 graph.show(xmax=2,xmin=-2,ymax=2,ymin=-2)
def steffenson_method(p_0, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 temporary = [] values = [] i = 1 temporary1 = (1, p_0, f_(p_0), abs(zeros-p_0), (abs(zeros-p_0))/(abs(p_0))) values.append(temporary1) while i <= max: p = n(p_0 - ((f_(p_0))^2)/(f_(p_0 +f_(p_0)) - f_(p_0))) temporary2 = (i, p, f_(p), abs(zeros-p), (abs(zeros-p))/(abs(p))) values.append(temporary2) print p if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
w = steffenson_method(.5, TOL, 1000, 1) ex = steffenson_method(.5, TOL, 1000, -1) y = steffenson_method(.5, TOL, 1000, a(0,1)) z = steffenson_method(.5, TOL, 1000, a(0,-1))
34.4823008849557 34.4823008849553 34.4823008849553 2 done 34.4823008849557 34.4823008849553 34.4823008849553 2 done 34.4823008849557 34.4823008849553 34.4823008849553 2 done 34.4823008849557 34.4823008849553 34.4823008849553 2 done
matw=matrix(w) matex=matrix(ex) maty=matrix(y) matz=matrix(z)
latex(matw)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 1 & 34.4823008849557 & 1.41378913957975 \times 10^{6} & 33.4823008849557 & 0.970999615039138 \\ 2 & 34.4823008849553 & 1.41378913957967 \times 10^{6} & 33.4823008849553 & 0.970999615039137 \end{array}\right)
latex(matex)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.50000000000000 & 3.00000000000000 \\ 1 & 34.4823008849557 & 1.41378913957975 \times 10^{6} & 35.4823008849557 & 1.02900038496086 \\ 2 & 34.4823008849553 & 1.41378913957967 \times 10^{6} & 35.4823008849553 & 1.02900038496086 \end{array}\right)
latex(maty)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 34.4823008849557 & 1.41378913957975 \times 10^{6} & 34.4967980299711 & 1.00042042278628 \\ 2 & 34.4823008849553 & 1.41378913957967 \times 10^{6} & 34.4967980299706 & 1.00042042278628 \end{array}\right)
latex(matz)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 34.4823008849557 & 1.41378913957975 \times 10^{6} & 34.4967980299711 & 1.00042042278628 \\ 2 & 34.4823008849553 & 1.41378913957967 \times 10^{6} & 34.4967980299706 & 1.00042042278628 \end{array}\right)
def steffenson_method_graph(p_0, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 temporary = [] values = [] i = 1 temporary1 = (p_0.real(),p_0.imag()) values.append(temporary1) while i <= max: p_1 = f_(p_0) p_2 = f_(p_1) p = n(p_0 - ((f_(p_0))^2)/(f_(p_0 +f_(p_0)) - f_(p_0))) values.append((p.real(),p.imag())) if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
gw = steffenson_method_graph(.5, TOL, 300, 1) gex = steffenson_method_graph(-1.5, TOL, 300, -1) gy = steffenson_method_graph(a(0,.5), TOL, 300, a(0,1)) gz = steffenson_method_graph(a(0,-1.75), TOL, 300, a(0,-1))
34.4823008849553 2 done
graph1 = point(gw,rgbcolor=(1,0,0)) graph2 = point(gex,rgbcolor=(0,1,0)) graph3 = point(gy,rgbcolor=(0,0,1)) graph4 = point(gz,rgbcolor=(0,.5,.5)) graph = graph1+graph2+graph3+graph4 graph.show(xmax=2,xmin=-2,ymax=2,ymin=-2) #graph
def halley_method(p_0, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 f_1(x) = derivative(f_,x) f_2(x) = derivative(f_1,x) temporary = [] values = [] i = 1 temporary1 = (1, p_0, f_(p_0), abs(zeros-p_0), (abs(zeros-p_0))/(abs(p_0))) values.append(temporary1) while i <= max: p = p_0 - (f_(p_0)*f_1(p_0))/((f_1(p_0)^2) - 0.5*(f_(p_0))*(f_2(p_0))) temporary1 = (i, p, f_(p), abs(zeros-p), (abs(zeros-p))/(abs(p))) values.append(temporary1) print p if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
w = halley_method(.5, TOL, 10, 1) ex = halley_method(.5, TOL, 10, -1) y = halley_method(.5, TOL, 10, a(0,1)) z = halley_method(.5, TOL, 10, a(0,-1))
0.783018867924528 0.983311377154950 0.999994044202479 1.00000000000000 1.00000000000000 1.00000000000000 5 done 0.783018867924528 0.983311377154950 0.999994044202479 1.00000000000000 1.00000000000000 1.00000000000000 5 done 0.783018867924528 0.983311377154950 0.999994044202479 1.00000000000000 1.00000000000000 1.00000000000000 5 done 0.783018867924528 0.983311377154950 0.999994044202479 1.00000000000000 1.00000000000000 1.00000000000000 5 done
matw=matrix(w) matex=matrix(ex) maty=matrix(y) matz=matrix(z)
latex(matw)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 1 & 0.783018867924528 & -0.624085646679841 & 0.216981132075472 & 0.277108433734940 \\ 2 & 0.983311377154950 & -0.0651019448197584 & 0.0166886228450503 & 0.0169718598124392 \\ 3 & 0.999994044202479 & -0.0000238229772541176 & 5.95579752060704 \times 10^{-6} & 5.95583299234241 \times 10^{-6} \\ 4 & 1.00000000000000 & -8.88178419700125 \times 10^{-16} & 2.22044604925031 \times 10^{-16} & 2.22044604925031 \times 10^{-16} \\ 5 & 1.00000000000000 & 0 & 0.000000000000000 & 0 \end{array}\right)
latex(matex)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.50000000000000 & 3.00000000000000 \\ 1 & 0.783018867924528 & -0.624085646679841 & 1.78301886792453 & 2.27710843373494 \\ 2 & 0.983311377154950 & -0.0651019448197584 & 1.98331137715495 & 2.01697185981244 \\ 3 & 0.999994044202479 & -0.0000238229772541176 & 1.99999404420248 & 2.00000595583299 \\ 4 & 1.00000000000000 & -8.88178419700125 \times 10^{-16} & 2.00000000000000 & 2.00000000000000 \\ 5 & 1.00000000000000 & 0 & 2.00000000000000 & 2.00000000000000 \end{array}\right)
latex(maty)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 0.783018867924528 & -0.624085646679841 & 1.27008603941852 & 1.62203759251039 \\ 2 & 0.983311377154950 & -0.0651019448197584 & 1.40246257149429 & 1.42626496964988 \\ 3 & 0.999994044202479 & -0.0000238229772541176 & 1.41420935099455 & 1.41421777378926 \\ 4 & 1.00000000000000 & -8.88178419700125 \times 10^{-16} & 1.41421356237309 & 1.41421356237310 \\ 5 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \end{array}\right)
latex(matz)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 1 & 0.783018867924528 & -0.624085646679841 & 1.27008603941852 & 1.62203759251039 \\ 2 & 0.983311377154950 & -0.0651019448197584 & 1.40246257149429 & 1.42626496964988 \\ 3 & 0.999994044202479 & -0.0000238229772541176 & 1.41420935099455 & 1.41421777378926 \\ 4 & 1.00000000000000 & -8.88178419700125 \times 10^{-16} & 1.41421356237309 & 1.41421356237310 \\ 5 & 1.00000000000000 & 0 & 1.41421356237310 & 1.41421356237310 \end{array}\right)
def halley_method_graph(p_0, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 f_1(x) = derivative(f_,x) f_2(x) = derivative(f_1,x) temporary = [] values = [] i = 1 while i <= max: p = p_0 - (f_(p_0)*f_1(p_0))/((f_1(p_0)^2) - 0.5*(f_(p_0))*(f_2(p_0))) temporary1 = (p.real(),p.imag()) values.append(temporary1) print p if abs(p - p_0) < TOL: print p print i print 'done' break i = i + 1 p_0 = p return values
gw = halley_method_graph(.5, TOL, 10, 1) gex = halley_method_graph(-.5, TOL, 10, -1) gy = halley_method_graph(a(0,.5), TOL, 10, a(0,1)) gz = halley_method_graph(a(0,-.5), TOL, 10, a(0,-1))
0.783018867924528 0.983311377154950 0.999994044202479 1.00000000000000 1.00000000000000 1.00000000000000 5 done -0.783018867924528 -0.983311377154950 -0.999994044202479 -1.00000000000000 -1.00000000000000 -1.00000000000000 5 done 0.783018867924528*I 0.983311377154950*I 0.999994044202479*I 1.00000000000000*I 1.00000000000000*I 1.00000000000000*I 5 done -0.783018867924528*I -0.983311377154950*I -0.999994044202479*I -1.00000000000000*I -1.00000000000000*I -1.00000000000000*I 5 done
graph1 = point(gw,rgbcolor=(1,0,0)) graph2 = point(gex,rgbcolor=(0,1,0)) graph3 = point(gy,rgbcolor=(0,0,1)) graph4 = point(gz,rgbcolor=(0,.5,.5)) graph = graph1+graph2+graph3+graph4 graph.show(xmax=2,xmin=-2,ymax=2,ymin=-2)
def secant_method(p_0, p_1, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 temporary = [] values = [] i = 2 q_0 = f_(p_0) q_1 = f_(p_1) temporary1 = (1, p_0, f_(p_0), abs(zeros-p_0), (abs(zeros-p_0))/(abs(p_0))) values.append(temporary1) while i <= max: p = n(p_1 - (q_1*(p_1 - p_0))/(q_1 - q_0)) temporary2 = (i, p, f_(p), abs(zeros-p), (abs(zeros-p))/(abs(p))) values.append(temporary2) if abs(p - p_1) < TOL: print i print p print 'done' break i = i + 1 p_0 = p_1 q_0 = q_1 p_0 = p p_1 = p q_1 = f_(p) return values
w = secant_method(0.5, 40, 10^(-10), 100, 1) ex = secant_method(0.5, 40, 10^(-10), 100, -1) y = secant_method(0.5, 40, 10^(-10), 100, a(0,1)) z = secant_method(0.5, 40, 10^(-10), 100, a(0,-1))
3 0.500014465332384 done 3 0.500014465332384 done 3 0.500014465332384 done 3 0.500014465332384 done
matw=matrix(w) matex=matrix(ex) maty=matrix(y) matz=matrix(z)
latex(matw)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 2 & 0.500014465332384 & -0.937492767019933 & 0.499985534667616 & 0.999942140344381 \\ 3 & 0.500014465332384 & -0.937492767019933 & 0.499985534667616 & 0.999942140344381 \end{array}\right)
latex(matex)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.50000000000000 & 3.00000000000000 \\ 2 & 0.500014465332384 & -0.937492767019933 & 1.50001446533238 & 2.99994214034438 \\ 3 & 0.500014465332384 & -0.937492767019933 & 1.50001446533238 & 2.99994214034438 \end{array}\right)
latex(maty)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 2 & 0.500014465332384 & -0.937492767019933 & 1.11804045791806 & 2.23601622640026 \\ 3 & 0.500014465332384 & -0.937492767019933 & 1.11804045791806 & 2.23601622640026 \end{array}\right)
latex(matz)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 1.11803398874989 & 2.23606797749979 \\ 2 & 0.500014465332384 & -0.937492767019933 & 1.11804045791806 & 2.23601622640026 \\ 3 & 0.500014465332384 & -0.937492767019933 & 1.11804045791806 & 2.23601622640026 \end{array}\right)
def secant_method_graph(p_0, p_1, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 temporary = [] values = [] i = 2 q_0 = f_(p_0) q_1 = f_(p_1) temporary = (p_0.real(),p_0.imag()) values.append(temporary) temporary1 = (p_1.real(),p_1.imag()) values.append(temporary1) while i <= max: p = n(p_1 - (q_1*(p_1 - p_0))/(q_1 - q_0)) temporary2 = (p.real(),p.imag()) values.append(temporary2) if abs(p - p_1) < TOL: print i print p print 'done' break i = i + 1 p_0 = p_1 p_1 = p q_0 = f_(p_0) q_1 = f_(p_1) return values
gw = secant_method_graph(0.5, 1.75, 10^(-10), 100, 1) gex = secant_method_graph(-0.5, -.75, 10^(-10), 100, -1) gy = secant_method_graph(a(0,0.5), a(0,.75), 10^(-10), 100, a(0,1)) gz = secant_method_graph(a(0,-0.5), a(0,-1.9), 10^(-10), 100, a(0,-1))
12 1.00000000000000 done 10 -1.00000000000000 done 10 1.00000000000000*I done 12 -1.00000000000000*I done
graph1 = point(gw,rgbcolor=(1,0,0)) graph2 = point(gex,rgbcolor=(0,1,0)) graph3 = point(gy,rgbcolor=(0,0,1)) graph4 = point(gz,rgbcolor=(0,.5,.5)) graph = graph1+graph2+graph3+graph4 graph.show(xmax=2,xmin=-2,ymax=2,ymin=-2)
def muller_method(p_0, p_1, p_2, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 h_1 = p_1 - p_0 h_2 = p_2 - p_1 delta_1 = (f_(p_1) - f_(p_0))/h_1 delta_2 = (f_(p_2) - f_(p_1))/h_2 d = (delta_2 - delta_1)/(h_2 + h_1) temporary = [] values = [] i = 3 temporary1 = (1, p_0, f_(p_0), abs(zeros-p_0), (abs(zeros-p_0))/(abs(p_0))) values.append(temporary1) temporary2 = (2, p_1, f_(p_1), abs(zeros-p_1), (abs(zeros-p_1))/(abs(p_1))) values.append(temporary2) temporary3 = (3, p_2, f_(p_2), abs(zeros-p_2), (abs(zeros-p_2))/(abs(p_2))) values.append(temporary3) while i < max: b = delta_2 + h_2*d D = (b^2 - 4*f_(p_2)*d)^(1/2) if (abs(b - D)) < (abs(b + D)): E = b + D else: E = b - D h = -2*f_(p_2)/E p = p_2 + h temporary2 = (i, p, f_(p), abs(zeros-p), (abs(zeros-p))/(abs(p))) values.append(temporary2) if abs(h) < TOL: print p print i print 'done' break p_0 = p_1 p_1 = p_2 p_2 = p h_1 = p_1 - p_0 h_2 = p_2 - p_1 delta_1 = (f_(p_1) - f_(p_0))/h_1 delta_2 = (f_(p_2) - f_(p_1))/h_2 d = (delta_2 - delta_1)/(h_2 + h_1) i = i + 1 return values
w = muller_method(.5, 2.0, 1.3, TOL, 100, 1) ex = muller_method(-.5, -2.0, -1.3, TOL, 100, -1) y = muller_method(a(0,.5), a(0,2.0), a(0,1.3), TOL, 100, a(0,1)) z = muller_method(a(0,-.5), a(0,-2), a(0,-1.3), TOL, 100, a(0,-1))
1.00000000000000 + 1.76122268991001e-24*I 9 done -1.00000000000000 + 1.76122268991001e-24*I 9 done -1.76122249269478e-24 + 1.00000000000000*I 9 done -1.76122249269478e-24 - 1.00000000000000*I 9 done
matw=matrix(w) matex=matrix(ex) maty=matrix(y) matz=matrix(z)
latex(matw)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 2 & 2.00000000000000 & 15.0000000000000 & 1.00000000000000 & 0.500000000000000 \\ 3 & 1.30000000000000 & 1.85610000000000 & 0.300000000000000 & 0.230769230769231 \\ 3 & 1.10850462100757 & 0.509906419514941 & 0.108504621007567 & 0.0978837786972347 \\ 4 & 0.937500304904910 - 0.0972351339863751i & -0.277292058482261 - 0.317029964384681i & 0.115589286563797 & 0.122637339558410 \\ 5 & 1.00245158317929 + 0.00327811632213315i & 0.00977766056269713 + 0.0132089995551326i & 0.00409344680024075 & 0.00408341408439371 \\ 6 & 0.999983584219219 + 0.0000489497544265850i & -0.0000656758822733527 + 0.000195789374814232i & 0.0000516290259163799 & 0.0000516298733992077 \\ 7 & 0.999999980934139 - 1.46962469681707 \times 10^{-8}i & -7.62634427831088 \times 10^{-8} - 5.87849845103237 \times 10^{-8}i & 2.40725305364605 \times 10^{-8} & 2.40725309954240 \times 10^{-8} \\ 8 & 0.999999999999995 - 1.69264559727271 \times 10^{-15}i & -1.90958360235527 \times 10^{-14} - 6.77058238909073 \times 10^{-15}i & 5.06514893244685 \times 10^{-15} & 5.06514893244688 \times 10^{-15} \\ 9 & 1.00000000000000 + 1.76122268991001 \times 10^{-24}i & 7.04489075964004 \times 10^{-24}i & 1.76122268991001 \times 10^{-24} & 1.76122268991001 \times 10^{-24} \end{array}\right)
latex(matex)
\left(\begin{array}{rrrrr} 1.00000000000000 & -0.500000000000000 & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 2 & -2.00000000000000 & 15.0000000000000 & 1.00000000000000 & 0.500000000000000 \\ 3 & -1.30000000000000 & 1.85610000000000 & 0.300000000000000 & 0.230769230769231 \\ 3 & -1.10850462100757 & 0.509906419514941 & 0.108504621007567 & 0.0978837786972347 \\ 4 & -0.937500304904910 - 0.0972351339863751i & -0.277292058482261 + 0.317029964384681i & 0.115589286563797 & 0.122637339558410 \\ 5 & -1.00245158317929 + 0.00327811632213315i & 0.00977766056269713 - 0.0132089995551326i & 0.00409344680024075 & 0.00408341408439371 \\ 6 & -0.999983584219219 + 0.0000489497544265850i & -0.0000656758822733527 - 0.000195789374814232i & 0.0000516290259163799 & 0.0000516298733992077 \\ 7 & -0.999999980934139 - 1.46962469681707 \times 10^{-8}i & -7.62634427831088 \times 10^{-8} + 5.87849845103237 \times 10^{-8}i & 2.40725305364605 \times 10^{-8} & 2.40725309954240 \times 10^{-8} \\ 8 & -0.999999999999995 - 1.69264559727271 \times 10^{-15}i & -1.90958360235527 \times 10^{-14} + 6.77058238909073 \times 10^{-15}i & 5.06514893244685 \times 10^{-15} & 5.06514893244688 \times 10^{-15} \\ 9 & -1.00000000000000 + 1.76122268991001 \times 10^{-24}i & -7.04489075964004 \times 10^{-24}i & 1.76122268991001 \times 10^{-24} & 1.76122268991001 \times 10^{-24} \end{array}\right)
latex(maty)
\left(\begin{array}{rrrrr} 1.00000000000000 & 0.500000000000000i & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 2 & 2.00000000000000i & 15.0000000000000 & 1.00000000000000 & 0.500000000000000 \\ 3 & 1.30000000000000i & 1.85610000000000 & 0.300000000000000 & 0.230769230769231 \\ 3 & 4.68253832726578 \times 10^{-18} + 1.10850462100757i & 0.509906419514941 - 2.55125492342538 \times 10^{-17}i & 0.108504621007567 & 0.0978837786972347 \\ 4 & 0.0972351339863748 + 0.937500304904909i & -0.277292058482261 - 0.317029964384680i & 0.115589286563797 & 0.122637339558410 \\ 5 & -0.00327811632213316 + 1.00245158317929i & 0.00977766056269713 + 0.0132089995551326i & 0.00409344680024076 & 0.00408341408439372 \\ 6 & -0.0000489497544265845 + 0.999983584219219i & -0.0000656758822733527 + 0.000195789374814230i & 0.0000516290259163795 & 0.0000516298733992073 \\ 7 & 1.46962469681775 \times 10^{-8} + 0.999999980934139i & -7.62634427831088 \times 10^{-8} - 5.87849845103508 \times 10^{-8}i & 2.40725305364647 \times 10^{-8} & 2.40725309954282 \times 10^{-8} \\ 8 & 1.69264559561835 \times 10^{-15} + 0.999999999999995i & -1.90958360235527 \times 10^{-14} - 6.77058238247328 \times 10^{-15}i & 5.06514893189400 \times 10^{-15} & 5.06514893189403 \times 10^{-15} \\ 9 & -1.76122249269478 \times 10^{-24} + 1.00000000000000i & 7.04488997077913 \times 10^{-24}i & 1.76122249269478 \times 10^{-24} & 1.76122249269478 \times 10^{-24} \end{array}\right)
latex(matz)
\left(\begin{array}{rrrrr} 1.00000000000000 & -0.500000000000000i & -0.937500000000000 & 0.500000000000000 & 1.00000000000000 \\ 2 & -2.00000000000000i & 15.0000000000000 & 1.00000000000000 & 0.500000000000000 \\ 3 & -1.30000000000000i & 1.85610000000000 & 0.300000000000000 & 0.230769230769231 \\ 3 & -4.68253832726578 \times 10^{-18} - 1.10850462100757i & 0.509906419514941 - 2.55125492342538 \times 10^{-17}i & 0.108504621007567 & 0.0978837786972347 \\ 4 & 0.0972351339863748 - 0.937500304904909i & -0.277292058482261 + 0.317029964384680i & 0.115589286563797 & 0.122637339558410 \\ 5 & -0.00327811632213318 - 1.00245158317929i & 0.00977766056269713 - 0.0132089995551327i & 0.00409344680024077 & 0.00408341408439373 \\ 6 & -0.0000489497544265850 - 0.999983584219219i & -0.0000656758822733527 - 0.000195789374814232i & 0.0000516290259163799 & 0.0000516298733992077 \\ 7 & 1.46962469681707 \times 10^{-8} - 0.999999980934139i & -7.62634427831088 \times 10^{-8} + 5.87849845103237 \times 10^{-8}i & 2.40725305364605 \times 10^{-8} & 2.40725309954240 \times 10^{-8} \\ 8 & 1.69264559561835 \times 10^{-15} - 0.999999999999995i & -1.90958360235527 \times 10^{-14} + 6.77058238247328 \times 10^{-15}i & 5.06514893189400 \times 10^{-15} & 5.06514893189403 \times 10^{-15} \\ 9 & -1.76122249269478 \times 10^{-24} - 1.00000000000000i & -7.04488997077913 \times 10^{-24}i & 1.76122249269478 \times 10^{-24} & 1.76122249269478 \times 10^{-24} \end{array}\right)
def muller_method_graph(p_0, p_1, p_2, TOL, max, zeros): var('i') var('p') f_(x) = x^4 - 1 h_1 = p_1 - p_0 h_2 = p_2 - p_1 delta_1 = (f_(p_1) - f_(p_0))/h_1 delta_2 = (f_(p_2) - f_(p_1))/h_2 d = (delta_2 - delta_1)/(h_2 + h_1) temporary = [] values = [] i = 3 temporary1 = ((p_0.real(),p_1.imag())) values.append(temporary1) temporary2 = ((p_1.real(),p_1.imag())) values.append(temporary2) temporary3 = ((p_2.real(),p_2.imag())) values.append(temporary3) while i < max: b = delta_2 + h_2*d D = (b^2 - 4*f_(p_2)*d)^(1/2) if (abs(b - D)) < (abs(b + D)): E = b + D else: E = b - D h = -2*f_(p_2)/E p = p_2 + h temporary2 = ((p.real(),p.imag())) values.append(temporary2) if abs(h) < TOL: print p print i print 'done' break p_0 = p_1 p_1 = p_2 p_2 = p h_1 = p_1 - p_0 h_2 = p_2 - p_1 delta_1 = (f_(p_1) - f_(p_0))/h_1 delta_2 = (f_(p_2) - f_(p_1))/h_2 d = (delta_2 - delta_1)/(h_2 + h_1) i = i + 1 return values
gw = muller_method_graph(.5, 2.0, 1.3, TOL, 100, 1) gex = muller_method_graph(-.5, -2.0, -1.3, TOL, 100, -1) gy = muller_method_graph(a(0,.5), a(0,2.0), a(0,1.3), TOL, 100, a(0,1)) gz = muller_method_graph(a(0,-.5), a(0,-2), a(0,-1.3), TOL, 100, a(0,-1))
1.00000000000000 + 1.76122268991001e-24*I 9 done -1.00000000000000 + 1.76122268991001e-24*I 9 done -1.76122249269478e-24 + 1.00000000000000*I 9 done -1.76122249269478e-24 - 1.00000000000000*I 9 done
graph1 = point(gw,rgbcolor=(1,0,0)) graph2 = point(gex,rgbcolor=(0,1,0)) graph3 = point(gy,rgbcolor=(0,0,1)) graph4 = point(gz,rgbcolor=(0,.5,.5)) graph = graph1+graph2+graph3+graph4 graph.show(xmax=2,xmin=-2,ymax=2,ymin=-2)