# HW 3-1: power method - Naguib

## 2285 days ago by bigdata2016

I have used power method to find the dominant Eigen value and corresponding normalized Eigen vector of the 7x7 matrix I used in HW1

A=matrix(7,7,[[5,4,6,2,7,1,5],[5,2,1,6,2,9,5],[3,4,2,7,7,8,8],[9,1,4,6,2,5,8],[4,1,8,5,4,4,6],[1,9,0,5,6,4,4],[8,10,0,3,8,3,8]]) X= matrix(7,1,[1,1,1,1,1,1,1]) print "A =" show(A) print "X(0) =", X.transpose()
 A = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrrrrr} 5 & 4 & 6 & 2 & 7 & 1 & 5 \\ 5 & 2 & 1 & 6 & 2 & 9 & 5 \\ 3 & 4 & 2 & 7 & 7 & 8 & 8 \\ 9 & 1 & 4 & 6 & 2 & 5 & 8 \\ 4 & 1 & 8 & 5 & 4 & 4 & 6 \\ 1 & 9 & 0 & 5 & 6 & 4 & 4 \\ 8 & 10 & 0 & 3 & 8 & 3 & 8 \end{array}\right) X(0) = [1 1 1 1 1 1 1] A = X(0) = [1 1 1 1 1 1 1]
for i in range(15): Y=A*X C=max(max(Y)) X=Y/C print "Iteration number", i+1 print "Y(%d)=AX(%d)"%(i+1,i) print "C = max(Y(%d)) = %f"%(i+1,C) #show(("X = ", X)) print "X(%d) ="%(i+1) , X.transpose().change_ring(RDF) show(" ")
 Iteration number 1 Y(1)=AX(0) C = max(Y(1)) = 14.621602 X(1) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 2 Y(2)=AX(1) C = max(Y(2)) = 33.548327 X(2) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 3 Y(3)=AX(2) C = max(Y(3)) = 33.548327 X(3) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 4 Y(4)=AX(3) C = max(Y(4)) = 33.548327 X(4) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 5 Y(5)=AX(4) C = max(Y(5)) = 33.548327 X(5) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 6 Y(6)=AX(5) C = max(Y(6)) = 33.548327 X(6) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 7 Y(7)=AX(6) C = max(Y(7)) = 33.548327 X(7) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 8 Y(8)=AX(7) C = max(Y(8)) = 33.548327 X(8) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 9 Y(9)=AX(8) C = max(Y(9)) = 33.548327 X(9) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 10 Y(10)=AX(9) C = max(Y(10)) = 33.548327 X(10) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 11 Y(11)=AX(10) C = max(Y(11)) = 33.548327 X(11) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 12 Y(12)=AX(11) C = max(Y(12)) = 33.548327 X(12) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 13 Y(13)=AX(12) C = max(Y(13)) = 33.548327 X(13) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 14 Y(14)=AX(13) C = max(Y(14)) = 33.548327 X(14) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 15 Y(15)=AX(14) C = max(Y(15)) = 33.548327 X(15) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] \newcommand{\Bold}[1]{\mathbf{#1}}\phantom{\verb!x!} Iteration number 1 Y(1)=AX(0) C = max(Y(1)) = 14.621602 X(1) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 2 Y(2)=AX(1) C = max(Y(2)) = 33.548327 X(2) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 3 Y(3)=AX(2) C = max(Y(3)) = 33.548327 X(3) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 4 Y(4)=AX(3) C = max(Y(4)) = 33.548327 X(4) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 5 Y(5)=AX(4) C = max(Y(5)) = 33.548327 X(5) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 6 Y(6)=AX(5) C = max(Y(6)) = 33.548327 X(6) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 7 Y(7)=AX(6) C = max(Y(7)) = 33.548327 X(7) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 8 Y(8)=AX(7) C = max(Y(8)) = 33.548327 X(8) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 9 Y(9)=AX(8) C = max(Y(9)) = 33.548327 X(9) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 10 Y(10)=AX(9) C = max(Y(10)) = 33.548327 X(10) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 11 Y(11)=AX(10) C = max(Y(11)) = 33.548327 X(11) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 12 Y(12)=AX(11) C = max(Y(12)) = 33.548327 X(12) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 13 Y(13)=AX(12) C = max(Y(13)) = 33.548327 X(13) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 14 Y(14)=AX(13) C = max(Y(14)) = 33.548327 X(14) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0] Iteration number 15 Y(15)=AX(14) C = max(Y(15)) = 33.548327 X(15) = [0.789168496853 0.748183211852 0.998495031712 0.913014192118 0.857309457529 0.718543042413 1.0]
X=X/norm(X) print "Dominant Eigen Value =", RDF(C) print "Normalized corresponding Eigen Vector is:" show(X.change_ring(RDF)) print "X^T . A . X =", (X.transpose() * A * X).change_ring(RDF)
 __main__:2: DeprecationWarning: The default norm will be changing from p='frob' to p=2. Use p='frob' explicitly to continue calculating the Frobenius norm. See http://trac.sagemath.org/13643 for details. Dominant Eigen Value = 33.5483274572 Normalized corresponding Eigen Vector is: \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{r} 0.343948816648 \\ 0.326085913691 \\ 0.435181062036 \\ 0.397925350814 \\ 0.373647167359 \\ 0.313167631671 \\ 0.435836982875 \end{array}\right) X^T . A . X = [33.5483274572] __main__:2: DeprecationWarning: The default norm will be changing from p='frob' to p=2. Use p='frob' explicitly to continue calculating the Frobenius norm. See http://trac.sagemath.org/13643 for details. Dominant Eigen Value = 33.5483274572 Normalized corresponding Eigen Vector is: X^T . A . X = [33.5483274572]