Skip to content
Josh Fogg edited this page Aug 8, 2024 · 1 revision
eigmax(matrix, max_iterations, tolerance)

Compute the largest eigenvalue of any matrix using the power method.

Parameters

  • matrix : ArrayLike
    Any matrix or matrix-like object.
  • max_iterations : int, optional
    Maximum number of iterations to spend improving approximation of the largest eigenvalue. If reached, whatever was the best approximation at that iteration will be returned. Default is stop at 1000 iterations.
  • tol: float, optional
    Tolerance with which to check convergence. Default is $10^{-7}$.

Returns

  • float The largest eigenvalue of the of the matrix, or the closest approximation if the maximum iteration count was reached.

Examples

If we have the matrix

>>> A = np.array([
 [1.    0.    0.5   0.5   0.5   0.5   0.5   0.    0.25 ],
 [0.    1.    0.5   0.5   0.5   0.    0.    0.5   0.25 ],
 [0.5   0.5   1.    0.5   0.5   0.25  0.25  0.25  0.25 ],
 [0.5   0.5   0.5   1.    0.5   0.25  0.25  0.25  0.25 ],
 [0.5   0.5   0.5   0.5   1.    0.25  0.25  0.25  0.25 ],
 [0.5   0.    0.25  0.25  0.25  1.    0.25  0.    0.125],
 [0.5   0.    0.25  0.25  0.25  0.25  1.    0.    0.5  ],
 [0.    0.5   0.25  0.25  0.25  0.    0.    1.    0.5  ],
 [0.25  0.25  0.25  0.25  0.25  0.125 0.5   0.5   1.   ]])

then we can compute maximum eigenvalue as

>>> eigmax(A)
3.517160078658142

Alternatively, we could use NumPy to compute all the eigenvalues and then take their maximum

>>> max(np.linalg.eigvals(A))
3.5171601498626526