Implement the power iteration algorithm to find the dominant eigenvector of a matrix.
Power iteration is an iterative algorithm for finding the eigenvector corresponding to the largest eigenvalue of a matrix. It's used in PageRank, PCA, and spectral clustering.
Algorithm:
Convergence: The rate depends on ∣λ1/λ2∣ - larger ratio means faster convergence.
After convergence, the dominant eigenvalue is: λ1=vTvvTAv=vTAv (when v is normalized)
matrix = [[2, 1], [1, 2]] max_iter = 100
{'eigenvector': [0.7071, 0.7071], 'eigenvalue': 3.0}Matrix analysis: The matrix [[2,1],[1,2]] has eigenvalues 3 and 1. Dominant eigenvalue: λ1=3 Corresponding eigenvector: [1,1] (normalized: [0.7071,0.7071])
Power iteration: Starting with v0=[1,0] (arbitrary):
Iteration 1: Av0=[2,1], normalized: [0.894,0.447] Iteration 2: Av1=[2.236,1.789], normalized: [0.781,0.625] ... Converges to [0.7071,0.7071]
Eigenvalue: vTAv=[0.7071,0.7071]⋅[2.12,2.12]=3.0