# POWER METHOD

n=7 A=random_matrix(ZZ,n) html('<p>This is my %s x %s matrix $A = %s$ created by Sage randomly.<p>'%(n,n,latex(A))) A.eigenvalues()
 This is my 7 x 7 matrix $A = \left(\begin{array}{rrrrrrr} 7 & -6 & 1 & 1 & 1 & 2 & 0 \\ 0 & -1 & -2 & -2 & -2 & 0 & 6 \\ 3 & 1 & -2 & 1 & 20 & -6 & 1 \\ 9 & -2 & 0 & 2 & 0 & -1 & -2 \\ 0 & 5 & -1 & 0 & 3 & 2 & 0 \\ -1 & 0 & -3 & 1 & -1 & -4 & 1 \\ -1 & -1 & 0 & -12 & -1 & -2 & 3 \end{array}\right)$ created by Sage randomly. [12.487229810116454?, -6.802980732708530? - 1.304865105006044?*I, -6.802980732708530? + 1.304865105006044?*I, 1.908779240516565? - 8.07377046124450?*I, 1.908779240516565? + 8.07377046124450?*I, 2.650586587133738? - 3.004431070390483?*I, 2.650586587133738? + 3.004431070390483?*I] This is my 7 x 7 matrix created by Sage randomly. [12.487229810116454?, -6.802980732708530? - 1.304865105006044?*I, -6.802980732708530? + 1.304865105006044?*I, 1.908779240516565? - 8.07377046124450?*I, 1.908779240516565? + 8.07377046124450?*I, 2.650586587133738? - 3.004431070390483?*I, 2.650586587133738? + 3.004431070390483?*I]
x= vector([1,1,1,1,1,1,1]) k=10 html('<p>$x_0 =%s$<p>'%( latex(x) ) ) for i in range(k): y=A*x ymod=y.apply_map(abs) c1=max(ymod) x=y/c1 print "Iteration number", i+1 html('$c_1=%s$ and $x_%s=%s$' %(c1.n(digits=7),i+1,latex(x.n(digits=7))) ) html('Dominant eigenvalue :$\lambda_{1} \\approx %s$'%(latex(c1.n(digits=5))))
 $x_0 =\left(1,\,1,\,1,\,1,\,1,\,1,\,1\right)$ Iteration number 1 $c_1=18.00000$ and $x_1=\left(0.3333333,\,-0.05555556,\,1.000000,\,0.3333333,\,0.5000000,\,-0.3888889,\,-0.7777778\right)$ Iteration number 2 $c_1=10.83333$ and $x_2=\left(0.3435897,\,-0.7641026,\,1.000000,\,0.5282051,\,-0.05128205,\,-0.2512821,\,-0.5846154\right)$ Iteration number 3 $c_1=7.964103$ and $x_3=\left(1.000000,\,-0.7153896,\,-0.1641983,\,0.8911784,\,-0.6877012,\,-0.2942692,\,-0.8937540\right)$ Iteration number 4 $c_1=14.29491$ and $x_4=\left(0.7515315,\,-0.3305856,\,-0.6560360,\,1.000000,\,-0.4242342,\,0.09477478,\,-0.8663063\right)$ Iteration number 5 $c_1=14.78518$ and $x_5=\left(0.4973570,\,-0.3183398,\,-0.3844092,\,0.7482352,\,-0.1406845,\,0.09437865,\,-1.000000\right)$ Iteration number 6 $c_1=12.20591$ and $x_6=\left(0.4754611,\,-0.5020471,\,-0.1383900,\,0.6976115,\,-0.1180236,\,0.01370446,\,-1.000000\right)$ Iteration number 7 $c_1=11.25414$ and $x_7=\left(0.6050324,\,-0.5669336,\,-0.1371915,\,0.7699180,\,-0.2397792,\,-0.02661012,\,-1.000000\right)$ Iteration number 8 $c_1=11.98412$ and $x_8=\left(0.6655940,\,-0.5189337,\,-0.2789908,\,0.8465877,\,-0.2895528,\,-0.006451903,\,-1.000000\right)$ Iteration number 9 $c_1=13.00326$ and $x_9=\left(0.6181452,\,-0.4642802,\,-0.2976122,\,0.8250119,\,-0.2458799,\,0.02563408,\,-1.000000\right)$ Iteration number 10 $c_1=12.85940$ and $x_10=\left(0.5789919,\,-0.4742648,\,-0.2535898,\,0.7866821,\,-0.2107533,\,0.01890032,\,-1.000000\right)$ Dominant eigenvalue :$\lambda_{1} \approx 12.859$  Iteration number 1 and Iteration number 2 and Iteration number 3 and Iteration number 4 and Iteration number 5 and Iteration number 6 and Iteration number 7 and Iteration number 8 and Iteration number 9 and Iteration number 10 and Dominant eigenvalue :