# Algebra : Math Question (answered!)

## 2131 days ago by bigdata2016

# Naguib: i defined these methods for your code to work def power_method(A,b): X= matrix(RDF,7,1,[1,1,1,1,1,1,1]) for i in range(b): Y=A*X C=max(max(Y)) X=Y/C show("Dominant Eigen value = ") show(C) show("Dominant Eigen vector = ") show(X) return C def power_method_err(A,b): C=power_method(A,b) GC=max(A.eigenvalues()) show("Power method Eigen value = ") show(C) show("Eigen value = ") show(GC) show("Error = ") show(abs(GC-C)) return abs(GC-C)
A = matrix(QQ, [[1, 2, 1, 2, 1, 2, 0],[0, 1, -2, 5, 0, 1, 0],[2, 0, 0, 1, 1, 1, 0],[1, 0, 1, 2, 4, 0, 1],[1, 1, 2, 0, 4, 1, 1],[1, 1, 6, 3, 0, 7, 0],[1, 1, 3, -1, 1, 6, 0]]) show(A)
time power_method(A, 20)
 10.3955390244 Time: CPU 0.02 s, Wall: 0.02 s 10.3955390244 Time: CPU 0.02 s, Wall: 0.02 s
time max(A.eigenvalues())
 10.39553902441960? Time: CPU 0.03 s, Wall: 0.04 s 10.39553902441960? Time: CPU 0.03 s, Wall: 0.04 s
time power_method_err(A, 20)
 1.15800702361e-11 Time: CPU 0.02 s, Wall: 0.02 s 1.15800702361e-11 Time: CPU 0.02 s, Wall: 0.02 s