Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168731
Image: ubuntu2004
a = ComplexField()#e.g.: a(4,2) = 4+2i b1 = .75 c1 = -.75 d1 = a(0,.92) #.5+i e1 = a(0,-.92)#.5-i TOL = 10^(-10) f(x) = x^4 -1
def steffenson(p_0): return (p_0 - ((f(p_0))^2/(f(p_0+f(p_0))-f(p_0))))
def steffenson_graph(p_0,tol,max): i = 1 data = [] data.append((p_0.real(),p_0.imag()))#collect the root values of p_0 while i<= max: p = steffenson(p_0) data.append((p.real(),p.imag()))# collect p's if abs(p - p_0) < tol: #print p break i = i + 1 p_0 = p return data
dat1 = steffenson_graph(b1,TOL,500) dat2 = steffenson_graph(c1,TOL,500) dat3 = steffenson_graph(d1,TOL,500) dat4 = steffenson_graph(e1,TOL,500)
#plot the points for the roots in red,green,purple, blue plot_b = point(dat1,rgbcolor=(1,0,0)) plot_c = point(dat2,rgbcolor=(0,1,0)) plot_d = point(dat3,rgbcolor=(.5,0,.5)) plot_e = point(dat4,rgbcolor=(0,0,1)) graph = plot_b+plot_c+plot_d+plot_e graph.show(xmin = -2, xmax=2,ymin=-2,ymax=2)
def steffenson_vals(p_0,tol,max,root): i = 1 data = [] temp = (0,p_0, f(p_0), abs(p_0-root), abs(p_0-root)/abs(root)) data.append(temp) while i<= max: p_1 = f(p_0) p_2 = f(p_1) p = steffenson(p_0) #the following storage code is to truncate the tables somewhat. Prof Zakeri said its okay. if i <= 10: temp = (i,p, f(p), abs(p-root), abs(p-root)/abs(root)) data.append(temp) else: if i % 10 == 0:# if (i mod 10) is 0 (multiple of 10) temp = (i,p, f(p), abs(p-root), abs(p-root)/abs(root)) data.append(temp) if abs(p - p_0) < tol: if i > 10: #stores the last recorded interation temp = (i,p, f(p), abs(p-root), abs(p-root)/abs(root)) data.append(temp) break i = i + 1 p_0 = p return data
val1 = steffenson_vals(b1,TOL,500,1) val2 = steffenson_vals(c1,TOL,500,1) val3 = steffenson_vals(d1,TOL,500,1) val4 = steffenson_vals(e1,TOL,500,1)
mat1 = matrix(val1) mat2 = matrix(val2) mat3 = matrix(val3) mat4 = matrix(val4)
latex(mat1)
\left(\begin{array}{rrrrr} 0.000000000000000 & 0.750000000000000 & -0.683593750000000 & 0.250000000000000 & 0.250000000000000 \\ 1 & 2.22699085264515 & 23.5965237789107 & 1.22699085264515 & 1.22699085264515 \\ 2 & 2.22573869596052 & 23.5412514622463 & 1.22573869596052 & 1.22573869596052 \\ 3 & 2.22448142609782 & 23.4858472194557 & 1.22448142609782 & 1.22448142609782 \\ 4 & 2.22321899905788 & 23.4303101562698 & 1.22321899905788 & 1.22321899905788 \\ 5 & 2.22195137026338 & 23.3746393683937 & 1.22195137026338 & 1.22195137026338 \\ 6 & 2.22067849454865 & 23.3188339413493 & 1.22067849454865 & 1.22067849454865 \\ 7 & 2.21940032614920 & 23.2628929503152 & 1.21940032614920 & 1.21940032614920 \\ 8 & 2.21811681869097 & 23.2068154599628 & 1.21811681869097 & 1.21811681869097 \\ 9 & 2.21682792517950 & 23.1506005242896 & 1.21682792517950 & 1.21682792517950 \\ 10 & 2.21553359798862 & 23.0942471864488 & 1.21553359798862 & 1.21553359798862 \\ 20 & 2.20228052063276 & 22.5228830696769 & 1.20228052063276 & 1.20228052063276 \\ 30 & 2.18842652015688 & 21.9365384980250 & 1.18842652015688 & 1.18842652015688 \\ 40 & 2.17391147234497 & 21.3340465906954 & 1.17391147234497 & 1.17391147234497 \\ 50 & 2.15866560894383 & 20.7140828352274 & 1.15866560894383 & 1.15866560894383 \\ 60 & 2.14260732355178 & 20.0751337791432 & 1.14260732355178 & 1.14260732355178 \\ 70 & 2.12564031343069 & 19.4154572816805 & 1.12564031343069 & 1.12564031343069 \\ 80 & 2.10764979994454 & 18.7330313772920 & 1.10764979994454 & 1.10764979994454 \\ 90 & 2.08849744582704 & 18.0254875064494 & 1.08849744582704 & 1.08849744582704 \\ 100 & 2.06801438895710 & 17.2900218697983 & 1.06801438895710 & 1.06801438895710 \\ 110 & 2.04599148626451 & 16.5232754937368 & 1.04599148626451 & 1.04599148626451 \\ 120 & 2.02216530754643 & 15.7211684221464 & 1.02216530754643 & 1.02216530754643 \\ 130 & 1.99619744115002 & 14.8786647040378 & 0.996197441150023 & 0.996197441150023 \\ 140 & 1.96764286784312 & 13.9894294639919 & 0.967642867843125 & 0.967642867843125 \\ 150 & 1.93589964412595 & 13.0453109968197 & 0.935899644125946 & 0.935899644125946 \\ 160 & 1.90012484744223 & 12.0355256520516 & 0.900124847442227 & 0.900124847442227 \\ 170 & 1.85908541290033 & 10.9453085722662 & 0.859085412900332 & 0.859085412900332 \\ 180 & 1.81087224862317 & 9.75353500358576 & 0.810872248623175 & 0.810872248623175 \\ 190 & 1.75229370020896 & 8.42817420471771 & 0.752293700208958 & 0.752293700208958 \\ 200 & 1.67739386800618 & 6.91662738282246 & 0.677393868006176 & 0.677393868006176 \\ 210 & 1.57298632205145 & 5.12209105817644 & 0.572986322051450 & 0.572986322051450 \\ 220 & 1.39960992704547 & 2.83732034828403 & 0.399609927045474 & 0.399609927045474 \\ 230 & 1.02008427064159 & 0.0827899190491834 & 0.0200842706415900 & 0.0200842706415900 \\ 235 & 1.00000000000000 & 0 & 0.000000000000000 & 0 \end{array}\right)
latex(mat2)
\left(\begin{array}{rrrrr} 0.000000000000000 & -0.750000000000000 & -0.683593750000000 & 1.75000000000000 & 1.75000000000000 \\ 1 & -0.869593576629500 & -0.428172164120321 & 1.86959357662950 & 1.86959357662950 \\ 2 & -0.950545742122759 & -0.183620513998629 & 1.95054574212276 & 1.95054574212276 \\ 3 & -0.990767100934639 & -0.0364232587301386 & 1.99076710093464 & 1.99076710093464 \\ 4 & -0.999629092032459 & -0.00148280663793010 & 1.99962909203246 & 1.99962909203246 \\ 5 & -0.999999381763949 & -2.47294191169090 \times 10^{-6} & 1.99999938176395 & 1.99999938176395 \\ 6 & -0.999999999998280 & -6.87983003899717 \times 10^{-12} & 1.99999999999828 & 1.99999999999828 \\ 7 & -1.00000000000000 & 0.000000000000000 & 2.00000000000000 & 2.00000000000000 \end{array}\right)
latex(mat3)
\left(\begin{array}{rrrrr} 0 & 0.920000000000000i & -0.283607040000000 & 1.35882302011704 & 1.35882302011704 \\ 1 & 0.0403835072874427 + 1.00030665628401i & -0.00856111904905910 - 0.161419166054193i & 1.38617358930693 & 1.38617358930693 \\ 2 & -0.0109566376378294 + 0.996967849214578i & -0.0127894625568997 + 0.0434238466836224i & 1.41985147658180 & 1.41985147658180 \\ 3 & -0.000554226373511876 + 0.999459309681602i & -0.00216284883835627 + 0.00221331077940353i & 1.41422334573543 & 1.41422334573543 \\ 4 & 8.02510786436310 \times 10^{-7} + 0.999996385850576i & -0.0000144565231885441 - 3.21000834114220 \times 10^{-6}i & 1.41421043932411 & 1.41421043932411 \\ 5 & 6.58079273827673 \times 10^{-11} + 1.00000000005343i & 2.13725037667700 \times 10^{-10} - 2.63231709573264 \times 10^{-10}i & 1.41421356236434 & 1.41421356236434 \\ 6 & -1.27307222093710 \times 10^{-17} + 1.00000000000000i & 5.09228888374840 \times 10^{-17}i & 1.41421356237310 & 1.41421356237310 \end{array}\right)
latex(mat4)
\left(\begin{array}{rrrrr} 0 & -0.920000000000000i & -0.283607040000000 & 1.35882302011704 & 1.35882302011704 \\ 1 & 0.0403835072874427 - 1.00030665628401i & -0.00856111904905910 + 0.161419166054193i & 1.38617358930693 & 1.38617358930693 \\ 2 & -0.0109566376378294 - 0.996967849214578i & -0.0127894625568997 - 0.0434238466836224i & 1.41985147658180 & 1.41985147658180 \\ 3 & -0.000554226373511876 - 0.999459309681602i & -0.00216284883835627 - 0.00221331077940353i & 1.41422334573543 & 1.41422334573543 \\ 4 & 8.02510786436310 \times 10^{-7} - 0.999996385850576i & -0.0000144565231885441 + 3.21000834114220 \times 10^{-6}i & 1.41421043932411 & 1.41421043932411 \\ 5 & 6.58079273827673 \times 10^{-11} - 1.00000000005343i & 2.13725037667700 \times 10^{-10} + 2.63231709573264 \times 10^{-10}i & 1.41421356236434 & 1.41421356236434 \\ 6 & -1.27307222093710 \times 10^{-17} - 1.00000000000000i & -5.09228888374840 \times 10^{-17}i & 1.41421356237310 & 1.41421356237310 \end{array}\right)
latex(mat2)
\left(\begin{array}{rrrrr} 0.000000000000000 & 1.80000000000000 & 0.572519083969466 & 2.80000000000000 & 2.80000000000000 \\ 1 & -1.59853766440737 & 0.658570253071242 & 0.598537664407367 & 0.598537664407367 \\ 2 & -1.01498966005305 & 0.990032350985353 & 0.0149896600530486 & 0.0149896600530486 \\ 3 & -1.00001002886760 & 0.999993314099445 & 0.0000100288675957128 & 0.0000100288675957128 \\ 4 & -1.00000000000447 & 0.999999999997020 & 4.47020198635073 \times 10^{-12} & 4.47020198635073 \times 10^{-12} \\ 5 & -1.00000000000000 & 1.00000000000000 & 0.000000000000000 & 0 \end{array}\right)