v9.1.1
Menu

Power Iteration for Dominant Eigenvector

hardFREEEigenvalues & EigenvectorsEigenanalysisCV: Mathematical Foundations

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:

  1. Start with random vector v0\mathbf{v}_0
  2. Iterate: vk+1=Avk∥Avk∥\mathbf{v}_{k+1} = \frac{A \mathbf{v}_k}{\|A \mathbf{v}_k\|}
  3. Converges when vk+1≈vk\mathbf{v}_{k+1} \approx \mathbf{v}_k

Convergence: The rate depends on ∣λ1/λ2∣|\lambda_1/\lambda_2| - larger ratio means faster convergence.

After convergence, the dominant eigenvalue is: λ1=vTAvvTv=vTAv\lambda_1 = \frac{\mathbf{v}^T A \mathbf{v}}{\mathbf{v}^T \mathbf{v}} = \mathbf{v}^T A \mathbf{v} (when v\mathbf{v} is normalized)

Example

Input
matrix = [[2, 1], [1, 2]]
max_iter = 100
Output
{'eigenvector': [0.7071, 0.7071], 'eigenvalue': 3.0}
Reasoning
  • Inputs: matrix is the symmetric 2×22 \times 2 matrix A=(2112)A = \begin{pmatrix}2 & 1\\ 1 & 2\end{pmatrix}; max_iter caps the updates; tol is how close consecutive unit vectors must be to stop.
  • Why it works here: A(11)=(33)A\begin{pmatrix}1\\1\end{pmatrix} = \begin{pmatrix}3\\3\end{pmatrix} and A(1−1)=(1−1)A\begin{pmatrix}1\\-1\end{pmatrix} = \begin{pmatrix}1\\-1\end{pmatrix}, so λ1=3\lambda_1 = 3, λ2=1\lambda_2 = 1. Each multiplication by AA grows the [1,1][1,1] direction 3 times faster than [1,−1][1,-1].
  • A few steps from v0=[1,0]\mathbf{v}_0 = [1, 0]: Av0=[2,1]A\mathbf{v}_0 = [2, 1] with norm 5\sqrt{5}, so v1=[0.8944,0.4472]\mathbf{v}_1 = [0.8944, 0.4472]; then v2=[0.7809,0.6247]\mathbf{v}_2 = [0.7809, 0.6247], v3=[0.7328,0.6805]\mathbf{v}_3 = [0.7328, 0.6805], v4=[0.7158,0.6983]\mathbf{v}_4 = [0.7158, 0.6983]. The gap to the limit shrinks by about λ2/λ1=1/3\lambda_2/\lambda_1 = 1/3 per step.
  • Limit: v=[1,1]/2=[0.7071,0.7071]\mathbf{v} = [1,1]/\sqrt{2} = [0.7071, 0.7071], unit norm since 0.5+0.5=10.5 + 0.5 = 1.
  • Eigenvalue: Av=[2.1213,2.1213]A\mathbf{v} = [2.1213, 2.1213], so vTAv=2⋅12⋅32=3.0\mathbf{v}^T A \mathbf{v} = 2 \cdot \frac{1}{\sqrt2} \cdot \frac{3}{\sqrt2} = 3.0.
  • Notice: −v-\mathbf{v} is an equally valid unit eigenvector; the sample shows the positive one. Both values are rounded to 4 decimal places under the keys 'eigenvector' and 'eigenvalue'.

Constraints

  • matrix: Square numpy array
  • max_iter: Maximum iterations (default 100)
  • tol: Convergence tolerance (default 1e-6)
  • Return: Dict with 'eigenvector' (unit norm) and 'eigenvalue'
  • Round to 4 decimal places

Learn this in

More from CV: Mathematical Foundations

solution.py

Test results

Sign in to run your code against the test cases.